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 07-11-2007, 07:32 PM
Member
 
Join Date: Jul 2007
Posts: 5
Emily is on a distinguished road
XML Help
Hi everyone,

I am trying to manipulate an xml file by reading the document, finding a specific attribute and changing its value. I have written the DOM and but I can't access the attribute or its value. Could someone help me with this. Im using the code below as practice:

<?xml version='1.0'?>
<catalog>
<book catagory="Technical">
<title>Java Programming</title>
<author>Lewis and Lofus</author>
</book>
<book catagory="Entertainment">
<title>Cosmo</title>
<author>Paul Lous</author>
</book>
<entry id="a1253">
</entry>
</catalog>

say for instance i was trying to change the value in the entry id attribute.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-11-2007, 08:10 PM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
Hey you can use Xpath inside the document to fetch the node like this
Code:
document.selectSingleNode("/catelog/entity");
Then get the attribute of it and you can either remove the node and add the fresh node with new attribute id.

I would recommend to use the XSLT to manage this if the XML transformations is very frequent

thanks
goldhouse
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-11-2007, 11:16 PM
Member
 
Join Date: Jul 2007
Posts: 5
Emily is on a distinguished road
Hi, thanks so much for responding. Unfortunately, I didnt completely understand what you were talking about. I am a 1st yr college student and this is my first time working with xml. I am trying to write the code in Java, does what you explained work with the JAVA API for xml?
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 09:52 PM.


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