Thread: Help with xml
View Single Post
  #4 (permalink)  
Old 03-28-2008, 06:29 PM
DonCash's Avatar
DonCash DonCash is offline
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 237
DonCash will become famous soon enoughDonCash will become famous soon enough
You could use xpath to search through an XML document.

Here is an example:

Code:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringComments(true); DocumentBuilder parser = dbf.newDocumentBuilder(); Document doc = parser.parse(yourfile.xml); String text = "Text to search for"; // look for the text somewhere in a nested Element XPath xpath = XPathFactory.newInstance().newXPath(); NodeList nodes = (NodeList)xpath.evaluate("//*[contains(text(),'" + text + "')]", doc, XPathConstants.NODESET); for (int i = 0, n = nodes.getLength(); i < n; i++) { Node node = nodes.item(i); String path; path = node.getNodeName() + '/' + node.getTextContent() }
This should search through the XML and return any values that contain your search text.
__________________
Did this post help you? Please
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
me!

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|| Don't forget to:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote