Java – string as document
•
Java
I'm focusing on parsing XML using XPath. It gives the following example to open a document:
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse("books.xml");
What I want to do is change it so that document reads the string variable I have created, not from the file How can I do this?
Solution
builder.parse(new InputSource(new StringReader("<some><xml></xml></some>")));
builder.parse(new InputSource(new StringReader("<some><xml></xml></some>")));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码