Results 1 to 8 of 8
  1. #1
    pankaj_salwan is offline Member
    Join Date
    Jul 2008
    Location
    india
    Posts
    35
    Rep Power
    0

    Default can i update the tag value of XMl file by other value(string

    can i update the tag value of XMl file by other value(string)

    like
    <title>it is good</title>

    by <title> hisssss</title>
    i am using DOM parser

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    pankaj_salwan is offline Member
    Join Date
    Jul 2008
    Location
    india
    Posts
    35
    Rep Power
    0

    Default

    that is to set the String..bt how to replace that string with other string..
    can u tel me thru certain code...
    Last edited by pankaj_salwan; 07-04-2008 at 07:45 AM.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Here is a simple code segment. Replace with appropriate values relevant to your code.

    Java Code:
    // Use the xpath as follows
    XPath myXPath = XPathFactory.newInstance().newXPath();
    XPathExpression myExpression = myXPath.compile("//title");
    
    // Get the node
    Node myNode = (Node)myExpresion.evaluate(document, XPathConstants.NODE);
     
    // Update the text with your value
    myNode.setTextContent("hisssss");
    Haven't test it. There can be spelling error. It should work, have a try.

  5. #5
    pankaj_salwan is offline Member
    Join Date
    Jul 2008
    Location
    india
    Posts
    35
    Rep Power
    0

    Default

    ok thanks...now tell me can i write the updated XML to a file..if yes then how???

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  7. #7
    pankaj_salwan is offline Member
    Join Date
    Jul 2008
    Location
    india
    Posts
    35
    Rep Power
    0

    Default

    yeah!! it updates but i have to write the updated file sm where as a new file..

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. JPanel won't update
    By ibanez270dx in forum New To Java
    Replies: 3
    Last Post: 01-06-2009, 08:59 PM
  2. [SOLVED] Update an XML file
    By Eranga in forum Advanced Java
    Replies: 4
    Last Post: 07-15-2008, 02:03 PM
  3. Update a record in Random access file
    By Rgfirefly24 in forum New To Java
    Replies: 2
    Last Post: 04-24-2008, 10:07 PM
  4. Using sql:update tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-13-2008, 11:49 PM
  5. Read a string from a txt file
    By cachi in forum Java Applets
    Replies: 1
    Last Post: 08-07-2007, 07:50 AM

Posting Permissions

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