android - 如何解析复杂的xml

标签 android xml

大家好,请告诉我如何解析以下 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/

相关文章:

Python:哪个 XML 解析库可以开箱即用地用于 Python 2.4 及更高版本?

android - 如何从处理程序更新 TextView 中的值?

javascript - 如何在已知的 XML 标签之间进行匹配?

php - Soap xml 在 php 中传递引用

android - iOS开发中的getter/setter类

java - 构建后 Maven *.xml 资源未更新

xml - 在我的 XML 编辑器中使用 XML Schema 进行代码自动完成

android - 尝试访问继承字段时出现 NullPointerException

android - 浏览器应用程序的 GCM key (带引荐来源网址)状态不活动

android - 如何在 fragment 之间传递数据