I'm not sure why you're creating a copy. Though as bob says the //list XPath
operation will try to start at the document, which a copied Element doesn't
have. You could fix this by not copying, by adding the new copied element to
a document or by changing your XPath expression to be

.//list

So that it starts relative to the current node, not the document.

James
----- Original Message -----
From: "Poon, Leon" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, March 16, 2002 7:17 PM
Subject: [dom4j-user] Question about selectSingleNode() method not working
on copies of Element


>
> I am trying to select a single node on a COPY of an element, but I am
> getting NullPointerException
> when I tried it. For example, I am getting the null pointer exception on
> node2 below. Is this a bug,
> or am I not using it properly? Right now, I am cloning the Document to get
> past this problem, but
> I think this is a very kludgy solution. Any suggestion is greatly welcome.
>
>
============================================================================
> ===================
> String str =
>
"<wine><prices><list>13.99</list><discounted>11.00</discounted></prices></wi
> ne>";
> SAXReader reader = new SAXReader();
> Document doc = reader.read(new StringReader(str));
>
> Element element = doc.getRootElement();
> Element node = (Element) element.selectSingleNode("//list");
> System.out.println("node: "+node.asXML());
>
> try {
>         Element elem2 = element.createCopy();
>         Element node2 = (Element) elem2.selectSingleNode("//list");
>         System.out.println("node2: "+node2.asXML());
> }
> catch (Exception e) {e.printStackTrace();}
>
> Document doc2 = doc.clone();
> Element elem3 = doc2.getRootElement();
> Element node3 = (Element) elem3.selectSingleNode("//list");
> System.out.println("node3: "+node3.asXML());
>
============================================================================
> ===================
>
> Leon
>
>
>
>
>
> This message contains information which may be confidential and
privileged.
> Unless you are the addressee  (or authorized to receive for the
addressee),
> you may not use, copy or disclose to anyone the message or any information
> contained in the message.  If you have received the message in error,
please
> advise the sender by reply e-mail, and delete or destroy the message.
>
> Thank you.
>
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to