Results 1 to 3 of 3

Thread: XML Help

  1. #1
    Emily is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

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

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Hey you can use Xpath inside the document to fetch the node like this
    Java 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

  3. #3
    Emily is offline Member
    Join Date
    Jul 2007
    Posts
    5
    Rep Power
    0

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •