gpt4 book ai didi

android - Android 中的简单 XML 解析

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:26 25 4
gpt4 key购买 nike

我的xml如下所示:

<.sUID>yPkmfG3caT6cxexj5oWy34WiUUjj8WliWit45IzFVSOt6gymAOUA==<./sUID>
<.Shipping>0.00<./Shipping>
<.DocType>SO<./DocType>

我如何在 Android 中解析这个简单的 xml?

最佳答案

制作文档:

public Document XMLfromString(String v){

Document doc = null;

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {

DocumentBuilder db = dbf.newDocumentBuilder();

InputSource is = new InputSource();
is.setCharacterStream(new StringReader(v));
doc = db.parse(is);

} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
e.printStackTrace();
}

return doc;

}

然后这样读:

Document doc = x.XMLfromString("<XML><sUID>yPkmfG3caT6cxexj5oWy34WiUUjj8WliWit45IzFVSOt6gymAOUA==</sUID> <Shipping>0.00</Shipping> <DocType>SO</DocType></XML>");

NodeList nodes = doc.getElementsByTagName("XML");

关于android - Android 中的简单 XML 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5548807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com