大家好,请让我知道如何解析以下xml字符串。我尝试了很多方法,但没有反应,请尽快给我一些想法。
谢谢
String responce ="
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:loginVerificationResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="ecgw">
<loginVerificationReturn xsi:type="ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap">
<item xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="soapenc:string">CLIENTID</key>
<value xsi:type="soapenc:integer">569604</value>
</item>
<item>
<key xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">AUTHORISED</key>
<value xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">TRUE</value>
</item>
</loginVerificationReturn>
</ns1:loginVerificationResponse>
</soapenv:Body>
</soapenv:Envelope>"
最佳答案
您可以使用XmlPullParser
。请参见doc here。文档中还有更多示例代码。
String responce = "your xml content here";
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(responce));
关于android - 如何解析复杂的xml,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26993798/