无法理解 TBXML 的工作原理
我遵循 TBXML 指南,它已成功安装到我的代码中,但他们提供的指南对我来说没有意义。我想从 XML 文档中获取一些值。他们启动此过程的一个示例是:
TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.w3schools.com/XML/note.xml"]] keep];< /code>
在 NSLog 中,对我来说,这将返回:
此示例 XML 文件包含以下内容:
有人能给我一个简单的例子吗我如何从这个 XML 文件中提取它的 ?他们的指南看起来确实相当简单,但我似乎无法理解它。
http://www.tbxml.co.uk/TBXML/Guides__-_Loading_an_XML_document.html 是他们的指南。
I followed the TBXML guide and it's been successfully installed into my code, but the guide they have doesn't make sense to me. I want to get some values from an XML document. An example they have of starting this process is:
TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://www.w3schools.com/XML/note.xml"]] retain];
In NSLog, for me this returns:
<TBXML: 0x4e3cc90>
This example XML file contains the following:
<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>
Could somebody give me a quick example on how from this XML file i would be able to extract the <body>
of this? Their guide does seem fairly straight forward looking at it, but I just can't seem to make sense of it.
http://www.tbxml.co.uk/TBXML/Guides_-_Loading_an_XML_document.html is their guide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Andrew,
看来一旦您使用 xml 文件初始化 TBXML(正如您所看到的那样),您就可以使用各种 API 来“遍历”文档中的元素。我还没有对此进行测试,但在您的示例中,“body”是“note”的子级,因此...首先从根元素中获取 note 元素,然后从 note 元素中提取 body 元素。
此时您应该能够遍历任何内容。
——弗兰克
Andrew,
It appears that once you init TBXML with the xml file, as it appears you have, you then 'traverse' elements in the document using various API. I haven't tested this but it would appear in your example that "body" is a child of "note", therefore... first get the note element and from the root element and extract the body element from the note element.
You should be able to traverse on anything at this point.
-- Frank