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

Recommended Answers

All 2 Replies

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.

hi,
thank you very much, I am giving it a try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.