import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class Util {
public static void main(String[] args) {
String xml="<employee><name>swati</name><id>1209202</id><department>audit</department></employee>";
System.out.println("get xml document from string xml);
stringToDom(xml) ;
System.out.println("document is ready for use");
}
public static void stringToDom(String xmlSource)
throws SAXException, ParserConfigurationException, IOException {
// Parse the given input
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(xmlSource)));
}
After document(doc) is created one can work on nodes,elements etc.
can save xml to files or can convert back to string and enjoy results.
I will post for more operations on xml documents.
No comments:
Post a Comment