大家好,请让我知道如何解析以下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>"
答案 0 :(得分:1)
您可以使用ksoap2 for Android来解析SOAP响应。一般来说,SOAP在Android上是一种痛苦。
对于一般的XML解析,我建议SimpleXML将XML映射到Java类/对象。
答案 1 :(得分:1)
您可以使用XmlPullParser
。请参阅doc here。文档中有更多示例代码。
String responce = "your xml content here";
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(responce));