The path:

   /RoutingInfo/MessageType/child::*

will only select child element nodes.

You want:

   /RoutingInfo/MessageType/text()

From:

   http://www.w3.org/TR/xpath#node-tests

   "Every axis has a principal node type. If an axis can contain elements,
   then the principal node type is element; otherwise, it is the type of
   the nodes that the axis can contain. Thus,

      * For the attribute axis, the principal node type is attribute.
      * For the namespace axis, the principal node type is namespace.
      * For other axes, the principal node type is element."

Dave



                                                                                
                                                       
                      "Boutelle, Jonathan"                                      
                                                       
                      <[EMAIL PROTECTED]         To:      "'[EMAIL PROTECTED]'" 
<[EMAIL PROTECTED]>        
                      rceone.com>                      cc:      (bcc: David N 
Bertoni/Cambridge/IBM)                                   
                                                       Subject: extracting text 
elements using xpath and xalan                         
                      07/09/2002 12:46 PM                                       
                                                       
                                                                                
                                                       
                                                                                
                                                       



Hello All,
I'm trying to extract a text element (the string "Response") from an xml
doc using xpath and xalan.  My doc is below


<RoutingInfo>
<MessageType foo="bar">Response</MessageType>
</RoutingInfo>


My xpath (which doesn't work) is as follows:
/RoutingInfo/MessageType/child::*


However, if I use the following xpath instead
/RoutingInfo/MessageType/
I get back a DOM node that has a child node of type text.


My code is as follows:
    InputSource in = new InputSource(new ByteArrayInputStream(docBytes));
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();

    dfactory.setNamespaceAware(false);
    org.w3c.dom.Document doc = dfactory.newDocumentBuilder().parse(in);
    Node n = XPathAPI.selectSingleNode(doc,
"RoutingInfo/MessageType/child::*");
    Node n=getNodeFromDom(doc,"/RoutingInfo/MessageType/");



I presume that my xpath query is wrong, but it looks correct to me.  Ideas?


Thanks in advance,
Jonathan Boutelle








Reply via email to