I have a string which contains XML data and I want to convert it to XML document object. How do I do that?
我有一个包含XML数据的字符串,我想将其转换为XML文档对象。我怎么做?
3 个解决方案
#1
8
say theString holds the XML,
说theString包含XML,
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(theString)));
More info here
更多信息在这里
#2
0
All you have to do is pass the string to the LoadXml method of the XmlDocument class. Then, you can use XPath to get the values of the elements/attributes in the document.
您所要做的就是将字符串传递给XmlDocument类的LoadXml方法。然后,您可以使用XPath获取文档中元素/属性的值。
#3
#1
8
say theString holds the XML,
说theString包含XML,
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(theString)));
More info here
更多信息在这里
#2
0
All you have to do is pass the string to the LoadXml method of the XmlDocument class. Then, you can use XPath to get the values of the elements/attributes in the document.
您所要做的就是将字符串传递给XmlDocument类的LoadXml方法。然后,您可以使用XPath获取文档中元素/属性的值。