-
Bug
-
Resolution: Fixed
-
P3
-
7
-
1.4
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2181850 | 7 | Joe Wang | P4 | Closed | Fixed | b14 |
JDK-2182539 | 6u18 | Joe Wang | P3 | Resolved | Fixed | b02 |
No prefix is treated as "" and null in SJSXP depending on if the element is in
no namespace or if in the default namespace.
In both situations there is no prefix but one returns null in a call to
XMLStreamReader.getPrefix() whilst the other returns "".
The following unit tests demonstrates this:
public void testInconsistentGetPrefixBehaviorWhenNoPrefix() throws Exception
{
String xml = "<root><child xmlns='foo'/></root>";
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader r = factory.createXMLStreamReader( new StringReader(
xml ) );
r.require( XMLStreamReader.START_DOCUMENT, null, null );
r.next();
r.require( XMLStreamReader.START_ELEMENT, null, "root" );
assertNull( r.getPrefix() ); // passes: prefix of root is null
r.next();
r.require( XMLStreamReader.START_ELEMENT, null, "child" );
assertNull( r.getPrefix() ); // fails: child also has no prefix but is ""
}
I appreciate that the specification is very unclear but my view is that there
should be some consistency in SJSXP.
Ideally there should also be some consistency with the Java landscape. Since
the XMLConstants file refers to the DEFAULT_NS_PREFIX as “”, I would like to
request that the above be rectified to return both as “”. This would tie into
getAttributePrefix() returning “” which it currently does.
The advantage of "" is that the prefix value is as it would be written out.
Regardless, it should be consistent for no prefix in getPrefix() and no prefix
in getAttributePrefix(int).------- Additional comments from jeffrey_sinclair Mon Feb 26 15:46:29 +0000 2007 -------
I've just found out that the StAX specification does say that no prefix should
be returned as null for XMLStreamReader.getPrefix().
It is a shame that the specification has used null instead of "".
SJSXP still needs to be consistent across its APIs but I'll leave it for the
developers to decide if they should go against the spec and use "" throughout
or sync up everything to use null.------- Additional comments from spericas Wed Feb 28 20:36:33 +0000 2007 -------
This one needs further evaluation.------- Additional comments from spericas Mon Mar 5 18:31:34 +0000 2007 -------
The method getPrefix() now returns "" (the empty string) in both cases, just like getAttributePrefix(). This
should make it easier to check for the lack of a prefix
no namespace or if in the default namespace.
In both situations there is no prefix but one returns null in a call to
XMLStreamReader.getPrefix() whilst the other returns "".
The following unit tests demonstrates this:
public void testInconsistentGetPrefixBehaviorWhenNoPrefix() throws Exception
{
String xml = "<root><child xmlns='foo'/></root>";
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader r = factory.createXMLStreamReader( new StringReader(
xml ) );
r.require( XMLStreamReader.START_DOCUMENT, null, null );
r.next();
r.require( XMLStreamReader.START_ELEMENT, null, "root" );
assertNull( r.getPrefix() ); // passes: prefix of root is null
r.next();
r.require( XMLStreamReader.START_ELEMENT, null, "child" );
assertNull( r.getPrefix() ); // fails: child also has no prefix but is ""
}
I appreciate that the specification is very unclear but my view is that there
should be some consistency in SJSXP.
Ideally there should also be some consistency with the Java landscape. Since
the XMLConstants file refers to the DEFAULT_NS_PREFIX as “”, I would like to
request that the above be rectified to return both as “”. This would tie into
getAttributePrefix() returning “” which it currently does.
The advantage of "" is that the prefix value is as it would be written out.
Regardless, it should be consistent for no prefix in getPrefix() and no prefix
in getAttributePrefix(int).------- Additional comments from jeffrey_sinclair Mon Feb 26 15:46:29 +0000 2007 -------
I've just found out that the StAX specification does say that no prefix should
be returned as null for XMLStreamReader.getPrefix().
It is a shame that the specification has used null instead of "".
SJSXP still needs to be consistent across its APIs but I'll leave it for the
developers to decide if they should go against the spec and use "" throughout
or sync up everything to use null.------- Additional comments from spericas Wed Feb 28 20:36:33 +0000 2007 -------
This one needs further evaluation.------- Additional comments from spericas Mon Mar 5 18:31:34 +0000 2007 -------
The method getPrefix() now returns "" (the empty string) in both cases, just like getAttributePrefix(). This
should make it easier to check for the lack of a prefix
- backported by
-
JDK-2182539 sjsxp issue 24: Inconsistent behavior for getPrefix() when no prefix
-
- Resolved
-
-
JDK-2181850 sjsxp issue 24: Inconsistent behavior for getPrefix() when no prefix
-
- Closed
-