Uploaded image for project: 'XMLBeans'
  1. XMLBeans
  2. XMLBEANS-311

XmlCursor.getTextValue returns concatenation of child text, comment, and processing instruction nodes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • Version 2.2.1
    • Version 2.2.1
    • Cursor
    • None
    • Microsoft Windows XP Professional Version 2002 (Service Pack 2)
      Intel Pentium 4 CPU 3.00GHZ

    Description

      According to the XmlBeans javadocs, if the XmlCursor corresponds to an element then non-text content such as comments and processing instructions are ignored. However, as the following test shows, this is not the case:

      String xml = "<element><!-A Comment->999<?PI A Processing Instruction?></element>";
      XmlObject xo = XmlObject.Factory.parse(xml);
      XmlCursor xc = xo.newCursor();
      xc.toFirstChild();
      System.out.println(xc.currentTokenType()); // Verify that we are positioned at the start of an element
      System.out.println(xc.getTextValue());

      This prints out:
      START
      A Comment 999A Processing Instruction

      Analysis:
      In this case, the call stack is as follows:
      org.apache.xmlbeans.impl.store.Cursor.getTextValue
      org.apache.xmlbeans.impl.store.Cursor._getTextValue
      org.apache.xmlbeans.impl.store.Locale.getTextValue

      In this method, the text value is built up with the text of instances of Cur for which the isText method returns true. I believe the org.apache.xmlbeans.impl.store.Cur.isText method should be as follows:

      boolean isText ( )

      { assert isPositioned(); return _pos > 0 && kindIsContainer(_xobj.kind()); }

      This would exclude comments and processing instructions.

      Attachments

        Activity

          People

            cezar Cezar Cristian Andrei
            cabryant Coram Bryant
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: