-
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.
-
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
-
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?