<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2523" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2>Hate to answer my own question, but as usual, I posted and
then figured it out a few minutes later. Seems the process of typing the problem
into an e-mail opens up the JDOM flood gates for me. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2>Simply put, I needed to "detatch" the currentElement from
the Document and then add it to a new Docuement object. Then I could aply other
XPath expressions to this new Document. Here's the code
snippet:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2>currentElement.detatch();</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2>Docuement newDoc = new
Document(currentElement);</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=573030018-27102005><FONT face=Arial
color=#0000ff size=2>-Kevin</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org
[mailto:jdom-interest-bounces@jdom.org] <B>On Behalf Of </B>Kevin L.
Cobb<BR><B>Sent:</B> Thursday, October 27, 2005 12:55 PM<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest] Question about List
from Xpath.selectNodes(doc)<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2>I'm using the XPath
functionality to set an XPATH String and then call the
selectNodes(sourceDocument) to get a list of Content back based on the XPATH.
When I iterate over the List of objects in the List (all should be Element
objects), I can see that everything is as expected. However, when I take one of
the Element objects in the List and convert it to a Document, I get the entire
Docuement back, versus just the Element I am using and all of its children. The
code looks like this:</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2>XPath myXpath =
XPath.newInstance("xpath to several elements downstream of the
root");</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2>Element
currentElement = null;</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2>Iterator itr =
myXpath..selectNodes(doc).iterator(); //doc is my XML
Document</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2>while
(itr.hasNext()) {</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005> <FONT face=Arial
size=2>currentElement = (Element) itr.next();</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2><SPAN
class=711013916-27102005><FONT face=Arial size=2> //Iterating
over the currentElement's children gives me what I expect, all child elements
names are output</FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2><SPAN
class=711013916-27102005><FONT face=Arial size=2> Iterator itr
= currentDiagnosis.getChildren().iterator();<BR> while
(itr.hasNext()) {<BR>
System.out.println(((Element) itr.next()).getName());<BR>
}<BR></FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2><SPAN
class=711013916-27102005><FONT face=Arial size=2> //But
putting the currentElement to a Document gives me my original Document back.
Wierd to me but perhaps this is by design.</FONT></SPAN></FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2><SPAN
class=711013916-27102005><FONT face=Arial size=2> Format
format = Format.getPrettyFormat();<BR> XMLOutputter
output = new
XMLOutputter(format);<BR> System.out.println(output.outputString(currentElement.getDocument()));<BR></FONT></SPAN></FONT></SPAN><SPAN
class=711013916-27102005><FONT face=Arial size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial size=2>Assuming this
behavior is by design, how can I get a Document object of my Elements in order
to write XPath expressions on these separatly?</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2>Thanks,</FONT></SPAN></DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2>Kevin</DIV></FONT></SPAN>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=711013916-27102005><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<P style="MARGIN-BOTTOM: 0in"></P>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>