- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如何在 iphone 上使用 xmlparsing 访问以下 XML 文件?
<?xml version="1.0" encoding="iso-8859-1"?>
<chapter>
<TITLE>Title &plainEntity;</TITLE>
<para>
<informaltable>
<tgroup cols="3">
<tbody>
<row><entry>a1</entry><entry morerows="1">b1</entry><entry>c1</entry></row>
<row><entry>a2<<?xml version="1.0" encoding="iso-8859-1"?>
<ADDRESS>
<CONTACT>
<NAME FIRST="Fred" LAST="Bloggs" NICK="Bloggsie" TITLE="Mr" />
<STREET HOME="5 Any Street" WORK="Floor 24, BigShot Tower" />
<CITY HOME="Little Town" WORK="Anycity" />
<COUNTY HOME="Anyshire" WORK="Anyshire" />
<POSTAL HOME="as plain text" WORK="text" />
<COUNTRY HOME="UK" WORK="UK" />
<PHONE HOME="as text" WORK="text" />
<FAX HOME="none" WORK="555" />
<MOBILE HOME="444" WORK="333" />
<WEB HOME="www.codehelp.co.uk" WORK="" />
<COMPANY>Full name of company here</COMPANY>
<GENDER>male</GENDER>
<BDAY>Add tags for year, month and day to make this more useful</BDAY>
<ANNI>some date long forgotten :-)</ANNI>
<SPOUSE>angry</SPOUSE>
<CHILDREN>Make sure this tag is one of the ones allowed to repeat in the DTD</CHILDREN>
<COMMENT>comments here</COMMENT>
<EMAILONE>Either use fixed tags like this, or change to a repeating tag</EMAILONE>
<EMAILTWO>second email line</EMAILTWO>
<EMAILTHREE>third</EMAILTHREE>
<EMAILFOUR>fourth</EMAILFOUR>
</CONTACT>
</ADDRESS>/entry><entry>c2</entry></row>
<row><entry>a3</entry><entry>b3</entry><entry>c3</entry></row>
</tbody>
</tgroup>
</informaltable>
</para>
&systemEntity;
<section id="about">
<title>About this Document</title>
<para>
<!-- this is a comment -->
</para>
</section>
</chapter>
最佳答案
SDK提供了两种解析XML的方式:libxml2和NSXMLParser。 libxml2 是最快的。要在您的项目中使用它,请转到您的 iPhone 应用程序项目的build设置并设置以下内容:
其他链接器标志 = -lxml2
header 搜索路径:$(SDKROOT)/usr/include/libxml2
然后从此页面下载 XPathQuery.m 和 XPathQuery.h:Using libxml2 for XML parsing and XPath queries in Cocoa ,其中还提供了有关如何使用它的教程。该 XPathQuery 类是一种解析 XML 的简化方法。我推荐它,除非您想自己编写相同的代码,但事实并非如此。
有了这个,做
NSString *string = nil; // put your html document here
NSData *htmlData = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *xpath = @"//row"; // any standard XPath expression
NSArray *nodesArray = PerformHTMLXPathQuery(htmlData, xpath);
NSDictionary *dict;
if (0<[nodesArray count]) {
dict = [nodesArray objectAtIndex:0];
}
此时文档中的元素应该在 dict
字典中。
关于iphone - 如何在 iphone 上使用 xmlparsing 解析 XML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5715174/
我目前在使用 XMLParse() 时遇到问题,正如标题所说,它不断抛出这个错误 An error occured while Parsing an XML document. Content is
抱歉,如果我让事情变得困惑。我编辑了整个问题。 我正在为托管在我的网络服务器上的网址使用 XMLPARSER。 我想将我的 url 列表从 url.add(map); 解析为 intent.putEx
看来我无法在 xml 中的表格中显示数据... - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPat
有人可以告诉我我需要做什么来解决这个问题 我有一个对象 UserPrefs *userpref 有一个变量叫userpref.userid,它是一个NSNumber 我正在解析 XML,这里的一切都运
使用 XmlParser 时,它会自动去除未使用的命名空间定义。它似乎没有检测到值中使用的命名空间。 示例代码:属性“type”的值为“xs:string”,它需要命名空间定义,但 XmlParser
我正在测试 XMLParsing 库(使用 Codable 协议(protocol)和 XML 请求) XMLParsing 库链接: https://github.com/ShawnMoore/XM
您好,我正在使用 ElementTree 解析来自 Kuler 的 xml feed。我才刚刚开始使用 python,但我被困在这里了。解析工作正常,直到我尝试检索包含“:”的任何节点例如 kuler
如何在 iphone 上使用 xmlparsing 访问以下 XML 文件? Title &plainEntity; a1b1c1 a2
我正在尝试使用两种不同的方法(xmlParse 和 httr::GET)请求一个 XML 文档,并期望得到相同的响应。我使用 xmlParse 得到的响应是我所期望的,但是使用 httr::GET 我
我正在为一些看起来像这样的古老代码编写测试用例: if (isXML(foo)) { try { bar = xmlParse(foo); } catch(any e) {
我什么时候想使用 xmlParse 函数而不是 xmlTreeParse 函数?此外,参数值 useInternalNodes=TRUE 或 asText=TRUE 何时有用? 例如: library
我想在来自 XML 的 android 端值的 Web View 中设置换行符。我在 XML 中使用 (/n) 标签,但它不被接受。我不知道如何在段落中换行,我也想设置来自 drawable 文件夹的
我是一名优秀的程序员,十分优秀!