解析复合类型 XML
我有一个 SOAP Web 服务,它返回这种格式的 XML
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:GetResponse>
<ret SOAP-ENC:arrayType="ns2:Map[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">ProtocolId</key>
<value xsi:type="xsd:string">1</value>
</item>
<item>
<key xsi:type="xsd:string">Title</key>
<value xsi:type="xsd:string">Some Title</value>
</item>
<item>
<key xsi:type="xsd:string">Text</key>
<value xsi:type="xsd:string"> Some Text </value>
</item>
</item>
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">ProtocolId</key>
<value xsi:type="xsd:string">2</value>
</item>
<item>
<key xsi:type="xsd:string">Title</key>
<value xsi:type="xsd:string">Another Title</value>
</item>
<item>
<key xsi:type="xsd:string">Text</key>
<value xsi:type="xsd:string">Another Text </value>
</item>
</item>
</ret>
</ns1:GetResponse>
</SOAP-ENV:Body>
如何为这种 XML 编写解析器。如果您有一些例子,将会有很大的帮助。
谢谢穆库尔
I have a SOAP web service that returns an XML in this format
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:GetResponse>
<ret SOAP-ENC:arrayType="ns2:Map[2]" xsi:type="SOAP-ENC:Array">
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">ProtocolId</key>
<value xsi:type="xsd:string">1</value>
</item>
<item>
<key xsi:type="xsd:string">Title</key>
<value xsi:type="xsd:string">Some Title</value>
</item>
<item>
<key xsi:type="xsd:string">Text</key>
<value xsi:type="xsd:string"> Some Text </value>
</item>
</item>
<item xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">ProtocolId</key>
<value xsi:type="xsd:string">2</value>
</item>
<item>
<key xsi:type="xsd:string">Title</key>
<value xsi:type="xsd:string">Another Title</value>
</item>
<item>
<key xsi:type="xsd:string">Text</key>
<value xsi:type="xsd:string">Another Text </value>
</item>
</item>
</ret>
</ns1:GetResponse>
</SOAP-ENV:Body>
How to write a parser for this kind of XML. If you have some examples, it will be of great help.
Thanks
Mukul
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我让它与这个解析器一起工作——
我用 Stringbuilder 从 XML 返回的值创建一个字符串,并直接使用这个字符串写入数据库。 parse 方法需要一个输入流、应用程序上下文和一个帮助我构建 sql 语句的字符串。我从解析器本身直接写入数据库。由于 XML 非常大(7MB),我必须这样做,否则我的 Android 设备在构建 1500 多个对象时会耗尽内存。
I made it work with this parser -
The Stringbuilder i have used to create a string out of the values returned by the XML and use this string directly to write to the database. The parse method takes an inputstream, the application context and a string that helps me build the sql statement. From the parser itself i write directly to the database. Since the XML was very large (7MB), i had to do it this way otherwise my android device would run out of memory while building 1500+ objects.