Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2007, 04:26 AM
Senior Member
 
Join Date: Jun 2007
Posts: 130
Jack is on a distinguished road
Help with xml
I have a problem when I want to do searches in java. It returns some kind of exception that says "the root is empty" I have the same problem when I want to delete elements in a XML
Can you send me an example ? I don't know how can i do that.
Thank you guys.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-02-2007, 02:58 AM
Senior Member
 
Join Date: Jun 2007
Posts: 164
Heather is on a distinguished road
This is strange.
Can you send the exact error ?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-02-2007, 03:00 AM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
please start to this tutorial
Working with XML: The Java/XML Tutorial
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 03-28-2008, 06:29 PM
DonCash's Avatar
Moderator
 
Join Date: Aug 2007
Location: London, UK
Posts: 220
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 me! || Don't forget to: Mark your Thread as Solved
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 12:51 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org