我正在开发一个应用程序,我需要在这个XML中解析一个XML我不知道有多少元素。如果我点击任何元素他们是子元素&另外我不知道这个子节中有多少元素另外我不知道子节有多少
这里可能是样本XML可以用于动态解析的一个开发的应用程序
<subject>
<subject_count>5</subject_count>
<subject_image>http://50.17.184.57/wm911/index4.jpeg</subject_image>
<subject_name>MCA</subject_name>
<subject_image>http://50.17.184.57/wm911/index4.jpeg</subject_image>
<subject_name>BCA</subject_name>
<subject_image>http://50.17.184.57/wm911/index4.jpeg</subject_image>
<subject_name>BSc</subject_name>
<subject_image>http://50.17.184.57/wm911/index4.jpeg</subject_image>
<subject_name>engg</subject_name>
<subject_image>http://50.17.184.57/wm911/index4.jpeg</subject_image>
<subject_name>BBA</subject_name>
<subject>
<topic>
<topic1>
<topic_count>3</topic_count>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>Adv C</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>Objective C</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>Java</topic_name>
</topic1>
<topic2>
<topic_count>4</topic_count>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>C</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>C++</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>.Net</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>network</topic_name>
</topic2>
<topic3>
<topic_count>2</topic_count>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>sic</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>computer</topic_name>
</topic3>
<topic4>
<topic_count>2</topic_count>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>math</topic_name>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>Adv computers</topic_name>
</topic4>
<topic5>
<topic_count>1</topic_count>
<topic_image>http://50.17.184.57/wm911/index4.jpeg</topic_image>
<topic_name>management</topic_name>
</topic5>
</topic>
<sub_topic>
<topic1.1>
<sub_topic_count>2</sub_topic_count>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>C program</sub_topic_name>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>system programing</sub_topic_name>
</topic1.1>
<topic1.2>
<sub_topic_count>3</sub_topic_count>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>XML parsing</sub_topic_name>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>Table</sub_topic_name>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>ipad</sub_topic_name>
</topic1.2>
<topic1.3>
<sub_topic_count>2</sub_topic_count>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>Java1</sub_topic_name>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>java2</sub_topic_name>
</topic1.3>
<topic2.1>
<sub_topic_count>2</sub_topic_count>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>POP</sub_topic_name>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>basic C</sub_topic_name>
</topic2.1>
<topic2.2>
<sub_topic_count>2</sub_topic_count>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>OOP</sub_topic_name>
<sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>basic C++</sub_topic_name>
</topic2.2>
<topic2.3>
<sub_topic_count>3</sub_topic_count>
<textname> TEXT1 </textname> <sub_topic_image>http://50.17.184.57/wm911/index4.jpeg</sub_topic_image>
<sub_topic_name>.Net2</sub_topic_name>
<video_url>http://192.168.1.128/xml/video/Citizen_7_Trailer_Mayor_09_07_10.m4v </video_url>
</topic2.3>
<topic2.4>
<sub_topic_count>2</sub_topic_count>
<pdf_url>http://50.17.184.57/wm911/STTcourse.pdf<pdf_url>
<ppt_url>http://192.168.1.128/xml/doc/PPT_SAMPLE.ppt </ppt_url>
</topic2.4>
</sub_topic>
答案 0 :(得分:1)
您可以使用libxml2来解析xml文件或文档。 PL。请参阅以下链接以供参考。
http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
你也可以在google中搜索libxml2来解析文件。
我建议TouchXML。
答案 1 :(得分:0)
查看Apple的XMLPerformance源代码,了解如何解析XML。
答案 2 :(得分:0)
我完全赞同Gomathi,以及你必须看到的那些链接query writting。
为您提供一些示例代码..
xPathQuery.h 在项目中放置xPathQuery.h和xPathQuery.m之后,只需调用
即可NSArray * results = PerformXMLXPathQuery(yourxmlDataObject,xpathQuery);
你会得到一系列的结果。一切都是最好的