Continued from the privious post to be more specific.

Say we have an XML document as follows:

<!-- ########### XML Document ########## -->
<PatientInfo>
    <Patient id="10099">
        <DemoInfo>
            <Age>39</Age>
            <Gender>Female</Gender>
        </DemoInfo>
    </Patient>
</PatientInfo>


// ########### Code Snippet ##############
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
Document xmlDoc = null;
Node node = null;
NodeIterator nodeIter = null;

try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    xmlDoc = builder.parse(filePath);

    node = XPathAPI.selectSingleNode(xmlDoc, "//[EMAIL PROTECTED]"10099']/*");
    // The 'node' should reference the <DemoInfo> element. Right?

    // ********************   QUESTION   ********************
    // The question is that whether the 'startNode' is referencing the
    // <DemoInfo> element or the root element, <PatientInfo>.
    nodeIter = XPathAPI.selectNodeIterator(node, "./*");

    // I was thinking that the 'nodeIter' should return the list of
    // subelements, including the <Age> and <Gender>, but it does not.
    // That's why I am trying to find out whether the 1st parameter in
    // all methods of XPathAPI is referencing the root element of DOM
    // or any node of the DOM passed to it
}
catch (Exception ex) {
    ex.printStackTrace();
}

Any comments? Thanks.


Pae




> In XPathAPI, all methods has a first parameter, "Node contextNode",
> and I am clear about that parameter.
> 
> Is that always referencing the root element of the DOM? Or, that
> supposed to be reference any node in the DOM. Thanks.
> 
> 
> Pae
> 
> 
> 
> 

Reply via email to