You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by bu...@apache.org on 2002/11/07 17:49:53 UTC

DO NOT REPLY [Bug 14360] New: - XPathAPI.selectSingleNode seems to truncate text node value

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14360>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14360

XPathAPI.selectSingleNode seems to truncate text node value

           Summary: XPathAPI.selectSingleNode seems to truncate text node
                    value
           Product: XalanJ2
           Version: 2.4
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: org.apache.xpath
        AssignedTo: xalan-dev@xml.apache.org
        ReportedBy: sujansky@pacbell.net


A DOM Node containing the following data is passed to a function that extracts 
the text value of the <FieldValue> element using XPathAPI:

<Field>
<FieldName>DateOfReading</FieldName>
<FieldValue>2002-10-17T11:00:00-08:00</FieldValue>
</Field>

The following method does this extraction.  Note where the debugging info is 
printed out by the "printSerialized(Node)" calls:

public static String getFieldValue(Node fieldNode) throws 
XMLDataAccessorException {
  Node tempParentNode = null;
  Node tempChildNode = null;
  String fieldValue = "";

//Print entire Node
printSerialized(fieldNode);
System.out.println("\n");

  try {
    //Use XPathAPI call to extract the appropriate node, using an XPath 
expression
    tempParentNode = XPathAPI.selectSingleNode(fieldNode,"FieldValue");

//Print <Field> Node
printSerialized(tempParentNode);
System.out.println("\n");

    //Some error checking
    if (tempParentNode ==  null)
      throw new XMLDataAccessorException();
    else {
      tempChildNode = XPathAPI.selectSingleNode(tempParentNode,"text()");
      if (tempChildNode == null)
        fieldValue = ""; //if there's no text() node, the value is the empty 
string for our purposes (this is not an Exception)
      else
        fieldValue = tempChildNode.getNodeValue();

//Print <FieldValue> Node
printSerialized(tempChildNode);
System.out.println("\n");

    }
  }
  catch (TransformerException te) {
      throw new XMLDataAccessorException();}

  // If all is well, return the value
  return fieldValue;
}

Running the method on the data produces the following debug output:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Field><FieldName>DateOfReading</FieldName><FieldValue>2002-10-17T11:00:00-08:00
</FieldValue></Field>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<FieldValue>2002-10-17T11:00:00-08:00</FieldValue>

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2002-

And "2002-" is returned from the method.  Sometimes, these date values get 
truncated in different positions, but the same data produces the same 
truncation.  Is this a configuration problem with the XPathAPI, an encoding 
problem with the data value, or indeed a bug?

I'm also including the code for printSerialized(Node) in case it's relevant:

static void printSerialized(Node theNode) {
      try {
        Serializer serializer = SerializerFactory.getSerializer
                             
(OutputProperties.getDefaultMethodProperties("xml"));
        serializer.setOutputStream(System.out);
        serializer.asDOMSerializer().serialize(theNode);
      }
      catch (IOException ioe) {ioe.printStackTrace();}
}