-4

The contents of my webpage is an XML file and I am saving this content in a string. I have to read the nodes of the XML file. How do I fetch the values of the nodes from this XML file?

Can someone please help me on this?

4
  • stackoverflow.com/questions/8484921/… Commented May 12, 2014 at 6:48
  • I tried to save the contents in an XML file and then read from it as a normal XML file, but I dont want to create a new file. Is there any way I can do this without saving the contents in a temp xml file? Commented May 12, 2014 at 6:48
  • stackoverflow.com/questions/373833/… Commented May 12, 2014 at 6:49
  • Most XML parsers can read from a string: xpp3, commons digester, xerces (and many more). Commented May 12, 2014 at 6:49

1 Answer 1

1

you can use a Document

In Java, how do I parse XML as a String instead of a file?

public static Document loadXMLFromString(String xml) throws Exception
{
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(xml));
    return builder.parse(is);

}

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.