Gordon, The two methods are not designed to return exactly the same info. While xmlText() has to always return a valid XML document with more flexible options, the newXMLStreamReader() is designed for speed to transfer the contents of the XML store.
Cezar > -----Original Message----- > From: Gordon Rogers [mailto:[EMAIL PROTECTED] > Sent: Monday, September 22, 2008 5:24 AM > To: [email protected] > Subject: XMLStreamReader namespace handling > > Hi > > I am using XMLBeans version 2.1.0 and have got a question about how the > XMLStreamReader handles namespaces and in particular why the semantics > used by the newXMLStreamReader() method and the xmlText() method are > different when passed the same set of XmlOptions. This is best > illustrated by an example: > > Map ns = new HashMap(); > ns.put( EBXML_NAMESPACE_URI, EBXML_NAMESPACE_PREFIX ); > > XmlOptions xmlOptions = new XmlOptions(); > xmlOptions.setSaveOuter(); > xmlOptions.setSaveSuggestedPrefixes( ns ) > > xmlOptions.setSaveAggressiveNamespaces().setSaveImplicitNamespaces( ns > ); > > MessageHeaderDocument messageHeaderDocument = > MessageHeaderDocument.Factory.newInstance(); > MessageHeaderDocument.MessageHeader messageHeader = > messageHeaderDocument.addNewMessageHeader(); > messageHeader.setVersion( "2.0" ); > FromDocument.From from = messageHeader.addNewFrom(); > PartyIdDocument.PartyId fromPartyId = from.addNewPartyId(); > fromPartyId.setType( "urn:nhs:names:partyType:ocs+serviceInstance" > ); > fromPartyId.setStringValue( "from_party_key" ); > > ... > > The output from the messageHeaderDocument.xmlText( xmlOptions ) looks > like: > <eb:MessageHeader > xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-head > er-2_0.xsd" eb:version="2.0"> > <eb:From> > <eb:PartyId > eb:type="urn:nhs:names:partyType:ocs+serviceInstance">from_party_key</eb > :PartyId> > </eb:From> > </eb:MessageHeader> > > The output from messageHeaderDocument.newXMLStreamReader( xmlOptions ) > looks like: > > <MessageHeader > xmlns="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header- > 2_0.xsd" > > xmlns:axis2ns1="http://www.oasis-open.org/committees/ebxml-msg/schema/ms > g-header-2_0.xsd" > axis2ns1:version="2.0"> > <From> > <PartyId > xmlns:axis2ns2="http://www.oasis-open.org/committees/ebxml-msg/schema/ms > g-header-2_0.xsd" > > axis2ns2:type="urn:nhs:names:partyType:ocs+serviceInstance">from_party_k > ey</PartyId> > </From> > </MessageHeader> > > As you can see the namespaces, whilst valid, have not been prefixed > correctly or managed aggressively when using the XMLStreamReader > approach. Does this seem like odd behaviour or is this expected? From > looking at the 2.1.0 source the only options newXMLStreamReader() pays > attention to are saveInner and saveOuter, why is this? > > I am writing an object that is a wrapper round an XmlObject and want to > expose an XMLStreamReader as part of that interface, but due to this > namespacing issue I'm considering exposing an InputStream instead, based > on the String returned from the xmlText() method. This seems a bit hacky > and I'm also concerned that it's not going to be the most efficient. I'm > using the result of that method as the input to a StAXOMBuilder so that > I can generate AXIOM classes for use in an axis 2 request. Has anyone > used a similar approach? > > Thanks in advance for any help with this. > > Gordon > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

