sjsxp
  1. sjsxp
  2. SJSXP-24

Inconsistent behavior for getPrefix() when no prefix

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      24

      Description

      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).

        Activity

        Hide
        jeffrey_sinclair added a comment -

        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.

        Show
        jeffrey_sinclair added a comment - 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.
        Hide
        Santiago Pericas-Geertsen added a comment -

        This one needs further evaluation.

        Show
        Santiago Pericas-Geertsen added a comment - This one needs further evaluation.
        Hide
        Santiago Pericas-Geertsen added a comment -

        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.

        Show
        Santiago Pericas-Geertsen added a comment - 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.

          People

          • Assignee:
            Santiago Pericas-Geertsen
            Reporter:
            jeffrey_sinclair
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: