[ http://issues.apache.org/jira/browse/XMLBEANS-222?page=all ]
Cezar Andrei resolved XMLBEANS-222:
-----------------------------------
Resolution: Fixed
There are two things happening here:
1. the semantics of XmlObject.newXMLStreamReader() is not exactly the same as
XMLInputFactory.newInstance().createXMLStreamReader(). The difference is that
it doesn't emit the start/end doc events, this is because in general an
XmlObject represents the content and there isn't a special case for a Document
XmlObject.
2. Once you get an XMLStreamReader the code calls imediately next() which
advances the reader to the next event after Soaf:Envelope, so efectively
missing the namespaces.
while (reader.hasNext()) {
int event = reader.next();
To catch the namespaces in question the test code has to be modified in one of
the two following ways:
1) add an option to start with START_DOC event
XmlOptions opts = new XmlOptions().setSaveOuter();
XMLStreamReader reader = object.newXMLStreamReader(opts);
2) or modify the logic to check the first event
XMLStreamReader reader = object.newXMLStreamReader();
boolean foundXsiNamespace = false;
int event = reader.getEventType();
do
{
if (event == XMLStreamReader.START_ELEMENT)
{
for (int i = 0; i < reader.getNamespaceCount(); i++)
{
if (reader.getNamespacePrefix(i).equals("xsi"))
{
foundXsiNamespace = true;
}
System.out.println(" testXMLStreamReader Namespace " +
reader.getNamespacePrefix(i) + " : " +
reader.getNamespaceURI(i));
}
}
event = reader.next();
}
while (reader.hasNext());
System.out.println(" xsi Namespace: " + foundXsiNamespace);
> new XmlStreamReader from XmlObject doesn't capture xsi namespace in outer
> element
> ---------------------------------------------------------------------------------
>
> Key: XMLBEANS-222
> URL: http://issues.apache.org/jira/browse/XMLBEANS-222
> Project: XMLBeans
> Type: Bug
> Components: XmlObject
> Versions: Version 2
> Environment: jdk 1.4.2_08, xmlbeans 2.0
> Reporter: Brian Bonner
> Attachments: XmlStreamReaderTest.java
>
> I'll attach a test case.
> I'm parsing a SOAP envelope which has the xsi namespace declared in the outer
> envelope. An element of the body uses the prefix for one of it's attributes
> (i.e. xsi:nil="true").
> reader.getNamespaceCount() doesn't seem to find it. If we create the
> XMLStream from a reader using an InputFactory (vs. using the creator from
> JSR173.class, it works, but will probably be slower.)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]