Results 1 to 4 of 4
  1. #1
    j_kathiresan is offline Member
    Join Date
    Feb 2008
    Posts
    12
    Rep Power
    0

    Default Replace an Xml attribute/element value via Java

    Hi,

    I've the XML content as String. I need to search for a name (which can be an attribute name or element name) and need to replace the value of it.

    Currently i'm using regular expression to find the tag and replacing it. The problem is it is taking more time.

    Even the XPATH api takes more time to process and set the value.

    I thought of using SAX parser but not sure how to set the value.

    Can anyone please help me on this?

    Thanks,
    Kathir

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    As far as I understand it, SAX is an API for XML parsing, not for XML writing. Anyone, please correct me if this is wrong.

  3. #3
    j_kathiresan is offline Member
    Join Date
    Feb 2008
    Posts
    12
    Rep Power
    0

    Default

    Fubarable...what is the best way to achieve the above.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by j_kathiresan View Post
    Fubarable...what is the best way to achieve the above.
    I don't know. If you're only changing the text in some nodes, then perhaps you can do this with SAX, either writing the unchanged text as it's read in, or writing out the changed text if the appropriate node is identified. But I don't think it would be easy to change the structure of the XML via SAX.

    But a warning: I'm no XML expert.

Similar Threads

  1. Replies: 3
    Last Post: 03-29-2010, 11:22 AM
  2. is there anyway to replace java.IO
    By nobody58 in forum Advanced Java
    Replies: 1
    Last Post: 03-19-2010, 02:19 PM
  3. Java XML DOM/Transformer and attribute ordering
    By BeMathis in forum Advanced Java
    Replies: 0
    Last Post: 10-14-2009, 07:49 PM
  4. Send object via web service, with a java.sql.Timestamp attribute
    By diegofsza in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 08-16-2009, 12:40 AM
  5. Invalid usebean class attribute - new to java
    By grinsalot in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-04-2008, 05:54 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
  •