如何使用 GDataXML 解析器解析此 xml?
<list>
<OrderData HASH="1408108039"></OrderData>
<OrderData HASH="208524692">
<id>97</id>
<customer>
<CustomerData HASH="2128670187"></CustomerData></customer>
<billingAddress></billingAddress><deliveryAddress></deliveryAddress>
<orderDetail>
<list>
<OrderDetailData HASH="516790072"></OrderDetailData>
<OrderDetailData HASH="11226247"></OrderDetailData>
<OrderDetailData HASH="11226247"></OrderDetailData>
</list>
</orderDetail>
<log/>
</OrderData>
<OrderData HASH="1502226778"></OrderData>
</list>
我找不到解决方案来查找 OrderDetailData
元素的数量?我还阅读了 http://iphonebyradix.blogspot。 com/2011/03/using-gdata-to-parse-xml-file.html 这个网址。
提前致谢。
编辑:
我再次解释我的要求。在此 xml 中将有多个 OrderData
元素。现在我必须计算特定 OrderData
元素中 OrderDetailData
元素的数量。假设,根据我的 xml,当前解析的 xml 有一个 OrderData
元素,名为 id
,其值为 97。现在,我必须计算有多少 OrderDetailData
元素包含在 OrderData中(其
id` 为 97)。
<list>
<OrderData HASH="1408108039"></OrderData>
<OrderData HASH="208524692">
<id>97</id>
<customer>
<CustomerData HASH="2128670187"></CustomerData></customer>
<billingAddress></billingAddress><deliveryAddress></deliveryAddress>
<orderDetail>
<list>
<OrderDetailData HASH="516790072"></OrderDetailData>
<OrderDetailData HASH="11226247"></OrderDetailData>
<OrderDetailData HASH="11226247"></OrderDetailData>
</list>
</orderDetail>
<log/>
</OrderData>
<OrderData HASH="1502226778"></OrderData>
</list>
I cannot find a solution to find the number of OrderDetailData
elements? I also read http://iphonebyradix.blogspot.com/2011/03/using-gdata-to-parse-xml-file.html this url.
Thanks in advance.
Edit:
I am explaining my requirement again. In this xml there will be multiple OrderData
element. Now I have to count the number of OrderDetailData
elemnts from a particular OrderData
element. Suppose that, according to my xml, the current parsed xml has one OrderData
element, named id
and its value is 97. Now, I have to count how many OrderDetailData
elements are contained in the OrderData(which
id` is 97).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个如何检索一些数据的简单示例。这个例子非常简单并且没有使用XPath表达式。我建议你先了解它是如何工作的,然后再使用XPath表达式。在我看来,如果您无法理解解析器的工作原理,那么使用 XPath 表达式是没有用的。
这是输出控制台:
希望有帮助。
编辑
test2.xml 包含您的文件,但您可以将其作为字符串传递。您还可以将参数作为字符串传递,如下所示:
This is a simple example how to retrieve some data. This example is very simple and not use XPath expression. I suggest you first understand how it works and then use XPath expression. In my opinion it is not useful to use XPath expression if you cannot understand how the parser works.
This is the output console:
Hope it helps.
Edit
test2.xml contains your file but you could pass it as a string. You can also pass as parameters as string like the following:
我发现 TouchXML 很容易解析,您可以直接从 xml 访问所需的数据
。 首先下载 TouchXML 并将 libxml2.dylib 框架添加到您的项目中。
更改“标题搜索路径”的构建设置并添加“/usr/include/libxml2”
将 TouchXML.h 导入到您的文件
Else
I found TouchXML easy in parsing and you can directly access data needed from xml
First of all Download TouchXML and add libxml2.dylib framework to your project.
change buildsetting for "Header Search Path" and add "/usr/include/libxml2"
Import TouchXML.h to your file
Else
如果 OrderDetailData 始终存在于数组的第二个对象中,您可以使用下面的方法,
在这个中您可以获取数组中的 OrderDetailData 元素,并且您可以在循环中解析数据。获取HASH值使用。
If the OrderDetailData is present in 2nd object of array all the time, u can use the below
In this u can get the OrderDetailData elements in the array, and u can parse the data in loop. to get HASH value use.
这是下面的代码,我已经尝试过了。我得到了正确的输出..检查一下
This is the below code, i have tried. I got the right output.. check out