----- Original Message -----
Sent: Sunday, November 17, 2002 4:12
PM
Subject: Re: [dom4j-user] XPath result
from a DOM and the Rest of DOM
Thank you for your reply as well as code
snippet. But that's not exactlly
what I was looking for.
My applogies if I did not explained well in
my prevous message. The
code snippet in your message will be able to
get the <ContactInfo>
subemelement fine. And I have no problem to
getting that.
My question was to get the rest of XML DOM,
excluding the prviously
selected sublelement, <ContactInfo>. To
wit, I am looking for a simple
way to get the result without parsing the XML document by
excluding
the previously selected subelement. The result I am
expecting to get
is as follows:
Initial XML:
<Patient>
<Age>39</Age>
<Gender>Female</Gender>
<ContactInfo>
<PhoneNumber>123-456-7890</PhoneNumber>
<EmailAddress>[EMAIL PROTECTED]</EmailAddress>
</ContactInfo>
</Patient>
The result XML:
<Patient>
<Age>39</Age>
<Gender>Female</Gender>
</Patient>
Thank you.
Any more comments?
Regards,
Pae
----- Original Message -----
Sent: Sunday, November 17, 2002 4:07
AM
Subject: Re: [dom4j-user] XPath
result from a DOM and the Rest of DOM
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/
|