xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: XmlOptions.setLoadAdditionalNamespaces does not appear to work
Date Wed, 10 Mar 2004 18:26:25 GMT
One way to bridge this is to write an adaptor which reads the
XMLInputStream and write SAX to XMLBeans.  Use the newSaxHandler from
the factories.

-----Original Message-----
From: Alexander Paransky [mailto:Alexander.Paransky@Overture.com] 
Sent: Wednesday, March 10, 2004 10:08 AM
To: xmlbeans-user@xml.apache.org; apara@standardset.com
Cc: Eric Vasilik
Subject: RE: XmlOptions.setLoadAdditionalNamespaces does not appear to
work

The XmlBeans version I am using is from org.apache.xmlbeans, the
XMLInputStream is from a weblogic package.  The
weblogic.xml.stream.XMLInputStream.getSubStream returns another
weblogic.xml.stream.XMLInputStream, so I am not quite sure how to
"bridge" XMLBeans and Weblogic parser without doing what I have done.

Do you recommend that I write an adapter between the two streams?  It's
not hard, but I also would have to adapt XMLEvent and ReferenceResolver.
Is there a better way of doing this?

Thanks

-AP_
http://www.myprofiles.com/profile/apara_business


-----Original Message-----
From: Eric Vasilik [mailto:ericvas@bea.com]
Sent: Wednesday, March 10, 2004 9:12 AM
To: apara@standardset.com; xmlbeans-user@xml.apache.org
Subject: RE: XmlOptions.setLoadAdditionalNamespaces does not appear to
work


Ah ha ... I see what's going on.  You are using the XMLOutputStream to
write an XMLInputStream to a String.  You then take the String and try
to parse it.  The problem is that XMLOutputStream does not generate
well-formed xml.  In this case, namespace decls are missing.  

Also, this will perform *very* poorly.  I suggest that you use the
version of parse to load an XMLInputStream directly into an XmlBean.
You will probably need to get a substream from your original
XmlInputStream.  This will bypass the creation of many unneeded objects
as well as bypass the saving and reparsing of your payload.

- Eric


-----Original Message-----
From: Alex Paransky [mailto:apara@standardset.com] 
Sent: Wednesday, March 10, 2004 4:31 AM
To: xmlbeans-user@xml.apache.org
Cc: Eric Vasilik
Subject: Re: XmlOptions.setLoadAdditionalNamespaces does not appear to
work

Here is the code which is being used to parse:

...
import weblogic.webservice.encoding.AbstractCodec;
import weblogic.xml.stream.XMLInputStream;
import org.apache.xmlbeans.XmlObject;
...

public class XMLBeansCodec
  extends AbstractCodec {

 public Object deserialize(
    final XMLName aName,
    final XMLInputStream aReader,
    final DeserializationContext aContext
    ) throws
    DeserializationException
  {
    try {
      //Convert the data to a StringBuffer
      //
      final StringWriter stringWriter = new StringWriter();
      final XMLOutputStream stream = 
XMLOutputStreamFactory.newInstance().newOutputStream(stringWriter);
      stream.add(aReader);
      stream.close();

      //Get the string buffer
      //
      final StringBuffer
        buffer =
          stringWriter.getBuffer();

      //Parse the document
      //
      return
        XmlObject.Factory.parse(
          new StringReader(buffer.toString())
        );
    }
    catch (final Exception e) {
      throw
        new DeserializationException(e);
    }
  }
.....
}


Alex Paransky wrote:

> I am extending the AbstractCodec and implemeting the deserialize() 
> function. The input IS coming from Weblogic's XMLInputStream. The 
> namespace is defined in the <soapenv:Envelope tag so entire XML taken 
> from the very beginning IS valid. By the time Weblogic calls 
> deserialize() function, it has already parsed the <soapenv:Envelope 
> tags and I only get a sub-XMLInputStream which only contains my 
> parameter document. When I call XmlObject.Factory.parse(...), I 
> encounter a reference to namespace xsi as in xsi:type="...". Namespace

> xsi is NOT defined in the parameter document. It's defined above, in 
> the section that Weblogic already parsed.
>
> Look, here is the entire XML/SOAP request:
>
> <soapenv:Envelope 
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <requestArray xmlns="http://www.overture.com/service/display">
> <request xsi:type="ns1:getStatusByTypeStatusFilterReqT" 
> xmlns:ns1="http://www.overture.com/service/display">
> <dataType>local/addTerm</dataType>
> </request>
> </requestArray>
> </soapenv:Body>
> </soapenv:Envelope>
>
> In the above request namespace xsi is defined in the <soapenv:Envelope

> as in:
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance".
>
> By the time I am called to parse the <soapenv:Body I am given only the

> following sub XML in the XMLInputStream:
>
> <requestArray xmlns="http://www.overture.com/service/display">
> <request xsi:type="ns1:getStatusByTypeStatusFilterReqT" 
> xmlns:ns1="http://www.overture.com/service/display">
> <dataType>local/addTerm</dataType>
> </request>
> </requestArray>
>
> The usage of xsi:type in the following line gives me the parser 
> exception:
>
> <request xsi:type="ns1:getStatusByTypeStatusFilterReqT" 
> xmlns:ns1="http://www.overture.com/service/display">
>
> The exception occurs because, as you said, when 
> XmlObject.Factory.parse() is called is it not aware of the xsi 
> namespace definition which has occured above. I can query Weblogic 
> API(s) and get the Map of namespace/uri entries that have been read 
> from the envelope, but there is no way to "inject" this information 
> into the XmlBeans parsing process.
>
> This is the problem that I am having.
>
> Please let me know if something is still not clear from this
explanation.
>
> Thanks.
> -AP_
>
>
>
>
>
>
>
>
>
>
> Eric Vasilik wrote:
>
>> I'm not quite fully understanding your situation. When your exception

>> happens, are you loading an XMLInputStream, or parsing XML text? If 
>> XML text, where does this text come from? Is it well formed (are all 
>> the namespaces defined)?
>>
>> -----Original Message-----
>> *From:* Alexander Paransky [mailto:Alexander.Paransky@Overture.com]
>> *Sent**:* Tuesday, March 09, 2004 10:12 AM
>> *To:* xmlbeans-user@xml.apache.org
>> *Cc:* Eric Vasilik
>> *Subject:* RE: XmlOptions.setLoadAdditionalNamespaces does not appear

>> to work
>>
>> Eric,
>>
>> That is exactly what I am trying to do, so then I have this problem. 
>> The Weblogic AbstractCodec.deserialize() is called and I am required 
>> to decode the XMLInputStream. Weblogic has already parsed out the 
>> SOAP header and I am only given the document (DOCUMENT/LITERAL 
>> encoding) which I now need to parse.
>>
>> Since Weblogic already parsed out the header, I can get at the 
>> namespaces defined in the <soapenv:Envelope by using various 
>> javax.xml APIs. The parameter which I am trying to parse however, 
>> does not explicitly re-declare the namespaces, but does make 
>> references to them, such as xsi:type="...".
>>
>> The overall XML starting with <soapenv:Envelope is valid. However, 
>> the subset which makes up the parameter, does not have enough 
>> namespace definitions to be parsed in isolation. I was hoping that 
>> setting additional namespaces on load would act as if those 
>> namespaces have been defined previously and help the "resolver" 
>> resolve the namespaces correctly in the XML fragment which is the 
>> parameter.
>>
>> Without this working, I am thinking I would have to "inject" the 
>> namespaces into the StringBuffer containing the XML to be parsed, 
>> prior to parsing it. It's not all that pretty. I have to search for 
>> an insertion point, and then insert the namespace declarations that I

>> can retrieve from the headers. It is a solution, but I was hoping 
>> that XmlOptions.setLoadAdditionalNamespaces() would accomplish this 
>> task.
>>
>> Is this not a common problem when using DOCUMENT/LITERAL encoding and

>> having XMLBeans parse out a sub-xml-document fragment?
>>
>> Thanks.
>> -AP_
>>
>>
>>
>> Content-Type: text/plain;
>> charset="us-ascii"
>> Subject: XmlOptions.setLoadAdditionalNamespaces does not appear to
work
>> Date: Tue, 9 Mar 2004 09:53:56 -0800
>> From: Eric Vasilik <ericvas@bea.com>
>>
>> Your description is not entirely clear to me, but the option to load
>> additional namespaces does not affect parsing. It simply adds the
given
>> namespaces after parsing. If the incoming xml to be parsed depends on
>> those namespaces to be correct, you will get a parse error, which
seems
>> to be what you are getting.
>>
>> - Eric
>>
>> -----Original Message-----
>> From: Alex Paransky [mailto:apara@standardset.com]
>> Sent: Tuesday, March 09, 2004 4:04 AM
>> To: xmlbeans-user@xml.apache.org
>> Subject: XmlOptions.setLoadAdditionalNamespaces does not appear to
work
>>
>> I am using Document Literal form of argument passing in my weblogic
>> webservice. An Axis client is creating a soap message such that the
xsi
>>
>> schema declaration is in the <soapenv:Envelope tag. Prior to parsing
of
>>
>> my document, I configure XmlOptions.setLoadAdditionalNamespaces to
add a
>>
>> proper reference to the xsi namespace. Even after doing this, I still
>> get an exception indicating that xsi is not a bound namespace.
>>
>> Here is an example of the XML that the client is sending:
>>
>> <soapenv:Envelope
>> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>> <soapenv:Body>
>> <requestArray xmlns="http://www.overture.com/service/display">
>> ..... document that uses xsi......
>>
>> As you can see, the document it's self does not define the xsi
schema.
>> It is defined in the <soapenv:Envelope tag.
>>
>> The particular exception occurs in the following code from Root.load
>> (xmlbeans v1):
>>
>> catch ( SAXParseException e )
>> {
>> context.abort();
>>
>> XmlError err =
>> XmlError.forLocation(
>> e.getMessage(),
>> (String) XmlOptions.safeGet( options,
>> XmlOptions.DOCUMENT_SOURCE_NAME ),
>> e.getLineNumber(), e.getColumnNumber(), -1 );
>>
>> throw new XmlException( err.toString(), e, err );
>> }
>>
>> Any ideas?
>>
>> Thanks.
>>
>> -AP_
>>
>> (crossposted to xmlbeans-user@xml.apache.org)
>> (crossposted to weblogic.developer.interest.xmlbeans)
>>
>> -- 
>> -AP_
>> http://www.myprofiles.com/member/profile/apara_personal
>> http://www.myprofiles.com/member/profile/apara_business
>>
>> -AP_
>> http://www.myprofiles.com/profile/apara_business
>>
>

-- 
-AP_
http://www.myprofiles.com/member/profile/apara_personal
http://www.myprofiles.com/member/profile/apara_business



- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


Mime
View raw message