So, what you really want is:
"//*[not( ancestor-or-self::ContactInfo ) ]"
Try that out and see what you get.

Enjoy!
Dave


Pae Choi wrote:
Dave,

It is partially working though, that was a nice XPath you gave. I
tested both Jaxen with DOM4J and XPE(seems like XPE also uses
Jaxen as well), the result was same as follows:

<Age>38</Age>
<Gender>Female</Gender>

It returns other sibing nodes excluding the <ContactInfo> element.
That's I wanted to see in that level, but I also need the other
elements, including their parent node, e.g., <Patient> element. To
wit, the result should be as follows:

<Patient>
    <Age>38</Age>
    <Gender>Female</Gender>
</Patient>

Any more comments? Thank you.

Regards,


Pae





----- Original Message -----
From: "David D. Lucas" <[EMAIL PROTECTED]>
To: "Pae Choi" <[EMAIL PROTECTED]>
Cc: "Benjamin Kopic" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Sunday, November 17, 2002 5:37 PM
Subject: Re: [dom4j-user] XPath result from a DOM and the Rest of DOM



Try the XPath syntax "/*/*[local-name()!='ContactInfo']" .
That should give you what you want.  I verified it with XPE, but have
not tried it on DOM4J.

Let me know if it works.  :-)
Later,
Dave


Pae Choi wrote:

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 -----
   *From:* Benjamin Kopic <mailto:[EMAIL PROTECTED]>
   *To:* Pae Choi <mailto:[EMAIL PROTECTED]>
   *Cc:* [EMAIL PROTECTED]
   <mailto:[EMAIL PROTECTED]>
   *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/


--

+------------------------------------------------------------+
| David Lucas                        mailto:[EMAIL PROTECTED]  |
| Lucas Software Engineering, Inc.   (740) 964-6248 Voice    |
| Unix,Java,C++,CORBA,XML,EJB        (614) 668-4020 Mobile   |
| Middleware,Frameworks              (888) 866-4728 Fax/Msg  |
+------------------------------------------------------------+
| GPS Location:  40.0150 deg Lat,  -82.6378 deg Long         |
| IMHC: "Jesus Christ is the way, the truth, and the life."  |
| IMHC: "I know where I am; I know where I'm going."    <><  |
+------------------------------------------------------------+

Notes: PGP Key Block=http://www.lse.com/~ddlucas/pgpblock.txt
IMHO="in my humble opinion" IMHC="in my humble conviction"
All trademarks above are those of their respective owners.




--

+------------------------------------------------------------+
| David Lucas mailto:[EMAIL PROTECTED] |
| Lucas Software Engineering, Inc. (740) 964-6248 Voice |
| Unix,Java,C++,CORBA,XML,EJB (614) 668-4020 Mobile |
| Middleware,Frameworks (888) 866-4728 Fax/Msg |
+------------------------------------------------------------+
| GPS Location: 40.0150 deg Lat, -82.6378 deg Long |
| IMHC: "Jesus Christ is the way, the truth, and the life." |
| IMHC: "I know where I am; I know where I'm going." <>< |
+------------------------------------------------------------+

Notes: PGP Key Block=http://www.lse.com/~ddlucas/pgpblock.txt
IMHO="in my humble opinion" IMHC="in my humble conviction"
All trademarks above are those of their respective owners.




-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing your web site with SSL, click here to get a FREE TRIAL of a Thawte Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to