Results 1 to 6 of 6
- 12-09-2011, 11:17 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Getting Child Nodes With XPath.evaluate on an Element as Opposed to a Node
I am trying to get an Element's child nodes using XPath, but I keep getting a 'cannot find symbol' error where I call XPath.evaluate. I think the trouble is I am passing in an Element not a Node (the examples I've seen online pass in a Node) - but I need to use the methods available to the Element object elsewhere so I don't have a Node object to pass in. Here is the code in question:
How would I go about getting a NodeList from an Element using xpath? If I need to pass in a Node, how would I convert my Element to a Node?Java Code:public static NodeList GetChildElements(Element parent, String xpath) { XPathFactory factory = XPathFactory.newInstance(); XPath xp = factory.newXPath(); NodeList nodes = null; nodes = (NodeList) xpath.evaluate(xpath, parent, XPathConstants.NODESET); return nodes; }
Thank you in advance!
- 12-10-2011, 10:21 AM #2
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Re: Getting Child Nodes With XPath.evaluate on an Element as Opposed to a Node
Eeeeesh this is driving me NUTS. I've gone through and modified my code so I can pass in a Node instead of an Element - I'm still getting the error:
cannot find symbol
symbol : method evaluate(org.w3c.dom.Document,org.w3c.dom.Node,jav ax.xml.namespace.QName)
location: interface javax.xml.xpath.XPath
return (NodeList)xPath.evaluate(xmlDocument, node, XPathConstants.NODESET);
All the mentioned classes are being imported so I'm not sure what the trouble is.
- 12-13-2011, 12:03 AM #3
Banned
- Join Date
- Dec 2011
- Posts
- 143
- Rep Power
- 0
- 12-13-2011, 04:39 PM #4
Member
- Join Date
- Jun 2010
- Posts
- 6
- Rep Power
- 0
Re: Getting Child Nodes With XPath.evaluate on an Element as Opposed to a Node
Oh! I don't call evaluate() on my XPath instance? I'll try calling it on XPath, see if that works. All the examples I've seen so far call evaluate() on an instance of XPath (XPath: evaluate(String expression, Object item) : XPath*«*javax.xml.xpath*«*Java by API).
Thanks!
- 12-15-2011, 09:44 AM #5
Re: Getting Child Nodes With XPath.evaluate on an Element as Opposed to a Node
The trouble is that you're trying to pass a Document instead of a String.
Get in the habit of using standard Java naming conventions!
- 12-21-2011, 10:45 PM #6
Banned
- Join Date
- Dec 2011
- Posts
- 143
- Rep Power
- 0
Similar Threads
-
Is it possible to use xpath with a Node or NodeList objects?
By omripe in forum XMLReplies: 6Last Post: 07-22-2011, 02:05 PM -
How to get complete child nodes of an xml
By poorni in forum XMLReplies: 1Last Post: 07-14-2010, 08:58 AM -
Get selected Node Value of a child element
By Ms.Ranjan in forum XMLReplies: 6Last Post: 10-06-2009, 09:31 PM -
How to add different menuitems to child node
By sudhakar.cheru in forum AWT / SwingReplies: 2Last Post: 09-16-2009, 06:32 AM -
How to get value of specific child node
By sito42 in forum New To JavaReplies: 1Last Post: 07-13-2009, 12:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks