0

hi there,
how can I change string to xml and vise verse in java, in addition how can I add values to xml according to element name ,
I can imagine something like "setValue(elementName, the value) ; as we are using in java,

any suggestions any help , please!
thanks in advance

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by knowledgelover
0

You might want to look into the Java XML API, W3C DOM API and its implementations like Xerces. The Xerces XML parsing library comes bundled with your Java runtime. A simple Xerces program:

public class Test {

   public static void main(final String[] args) throws Exception {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();      
      DocumentBuilder builder = factory.newDocumentBuilder();
      System.out.println(factory + "\n" + builder);
      InputSource in = new InputSource(new StringReader(
            "<?xml version='1.0'?><root><child value='1'/></root>"));
      // The doc now contains the entire XML hierarchy
      Document doc = builder.parse(in);
   }

}

BTW, if all you need to do is manipulate your XML files in memory, go for a Java specific solution like JDOM.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.