If I understand you correctly, the following will return <Patient> element:


SAXReader reader = new SAXReader();
Document document = reader.read( new File( "patient_records.xml" ) );
Element contactInfo = document.selectSingleNode( "//ContactInfo", "." );
Element patient = contactInfor.getParent();


Then you can use the Node API to traverse the <Patient> element returned.

Also, if <Patient> is the root element, then you can do the following:

SAXReader reader = new SAXReader();
Document document = reader.read( new File( "patient_records.xml" ) );
Element patient = document.getRootElement();



Best regards

Ben


On Sat, 2002-11-16 at 23:52, Pae Choi wrote:
Say we have an XML document as follows:

<Patient>
    <Age>39</Age>
    <Gender>Female</Gender>
    <ContactInfo>
        <PhoneNumber>123-456-7890</PhoneNumber>
        <EmailAddress>[EMAIL PROTECTED]</EmailAddress>
    </ContactInfo>
</Patient>

And we use the XPath to only get the <ContactInfo>, e.g.,
"//ContactInfo" which should get the result as follows;

    <ContactInfo>
        <PhoneNumber>123-456-7890</PhoneNumber>
        <EmailAddress>[EMAIL PROTECTED]</EmailAddress>
    </ContactInfo>

My question is:

[Q] Is there way to get the rest of XML document in a simple
      way. The rest of XML document should be as follows;

<Patient>
    <Age>39</Age>
    <Gender>Female</Gender>
</Patient>

Any comments? Thank you.

Regards,


Pae


-- 
benjamin kopic
m: +44 (0)780 154 7643
t: +44 (0)20 7794 3090
e: [EMAIL PROTECTED]
w: http://www.panContext.com/

Reply via email to