iOS TBXML的使用

解析XML/JSON都要事先了解XML/JSON的结构,对于手机来说可能用JSON更轻量级,但是用Java做服务端的话可能更倾向于使用XML,一下介绍TBXML官方示例。

<?xml version="1.0"?>
<authors>
    <author name="J.K. Rowling">
        <book title="Harry Potter and the Philosopher‘s Stone" price="119.99">
            <description>
                Harry potter thinks he is an ordinary boy - until he is rescued from a beetle-eyed giant of a man, enrolls at Hogwarts School of Witchcraft and Wizardry, learns to play quidditch and does battle in a deadly duel.
            </description>
        </book>
        <book title="Harry Potter and the Chamber of Secrets" price="8.99">
            <description>
                When the Chamber of Secrets is opened again at the Hogwarts School for Witchcraft and Wizardry, second-year student Harry Potter finds himself in danger from a dark power that has once more been released on the school.
            </description>
        </book>
    </author>
    <author name="Douglas Adams">
        <book title="The Hitchhiker‘s Guide to the Galaxy" price="15.49">
            <description>
                Join Douglas Adams‘s hapless hero Arthur Dent as he travels the galaxy with his intrepid pal Ford Prefect, getting into horrible messes and generally wreaking hilarious havoc.
            </description>
        </book>
        <book title="The Restaurant at the End of the Universe " price="14.36">
            <description>
                Arthur and Ford, having survived the destruction of Earth by surreptitiously hitching a ride on a Vogon constructor ship, have been kicked off that ship by its commander. Now they find themselves aboard a stolen Improbability Drive ship commanded by Beeblebrox, ex-president of the Imperial Galactic Government and full-time thief.
            </description>
        </book>
    </author>
</authors>

主要的数据结构有

typedef struct _TBXMLElement {
char * name;
char * text;
TBXMLAttribute * firstAttribute;
struct _TBXMLElement * parentElement;
struct _TBXMLElement * firstChild;
struct _TBXMLElement * currentChild;
struct _TBXMLElement * nextSibling;
struct _TBXMLElement * previousSibling;
} TBXMLElement;
typedef struct _TBXMLAttribute {
char * name;
char * value;
struct _TBXMLAttribute * next;
} TBXMLAttribute;

读取一个XML文件或从XML字符串或从NSData读取方式为

TBXML *tbxml = [[TBXML alloc] initWithXMLFile:@"books.xml"];
TBXML *tbxml = [[TBXML alloc] initWithXMLFile:@"books" fileExtension:@"xml"];
TBXML *tbxml = [[TBXML alloc] initWithXMLString:xmlString];
TBXML *tbxml = [[TBXML alloc] initWithXMLData:xmlData];

iOS TBXML的使用,布布扣,bubuko.com

时间: 2024-08-26 05:00:50

iOS TBXML的使用的相关文章

IOS中使用TBXML解析XML

IOS SDK自带的NSXML框架是采用SAX模式解析的,是基于事件驱动型的,主要解析工作在NSXMLParseDelegate中完成,解析过程中遇到开始标签.结束标签.文档开始.文档结束和字符串时触发Delegate中的方法完成解析,这种方式使用起来还是比较麻烦的.在实际工作中,我们可以选用一个比较简单易用的第三方框架TBXML,其下载地址为:https://github.com/71squared/tbxml 下载完成解压后,我们只需要将TBXML-Headers和TBXML-Code文件夹

IOS要用到的东西

code4app.com 这网站不错,收集各种 iOS App 开发可以用到的代码示例 cocoacontrols.com/ 英文版本的lib收集 objclibs.com/ 精品lib的收集网站 http://www.ityran.com/forum-61-1.html 泰然代码仓库 ---------------------- emoji ---------------------- http://www.easyapns.com/category/just-for-fun http://w

iOS GET、POST数据解析

在实际开发中,JSON数据解析更简单易行,一般均使用json数据解析,因此,程序猿们请务必和后台搞好关系,让他给你json数据.    XML解析: ios SDK提供了NSXMLParser和libxml2两个类库,另外还有很多第三方类库可选:TBXML.TouchXML.KissXML.TinyXML和GDataXML. 解析XML通常有两种方式:DOM和SAX DOM解析XML时,读入整个XML文档并构建一个驻留内存的树结构(节点树),遍历树结构可以检索任意XML节点,读取它的属性和值.

iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)

iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角) 2015-04-05 15:25 2482人阅读 评论(1) 收藏 举报开源框架 图像: 1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.      下载:https://github.com/mwaterfall/MWPhotoBrowser目前比较活跃的社区仍旧是Github,

iOS(iPhone,iPad))开发(Objective-C)开发库常用库索引

http://www.code4app.com 这网站不错,收集各种 iOS App 开发可以用到的代码示例 http://www.cocoacontrols.com/ 英文版本的lib收集 http://www.objclibs.com/ 精品lib的收集网站 http://www.ityran.com/forum-61-1.html 泰然代码仓库 ---------------------- emoji ---------------------- http://www.easyapns.c

iOS常用第三方框架大全

常用第三方 今天就给大家总结一下,我们在项目中用到最多的第三方,免去了大家花时间去搜索,在这里大家进行了全面的总结. 1. 编程框架 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:iOS快速简单集成国内三大平台分享 地址:https://github.com/xumeng/XMShareModule 2. 加载提示 1:hud提示框 地址:https://github.com/jdg/MBProgressHU

常用iOS的第三方框架

图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作.      下载:https://github.com/mwaterfall/MWPhotoBrowser 目前比较活跃的社区仍旧是Github,除此以外也有一些不错的库散落在Google Code.SourceForge等地方.由于Github社区太过主流,这里主要介绍一下Github里面流

iOS开发——面试总结(一)

面试总结(一) 通过网络搜寻和自己总结经历找了一些IOS面试经常被问道的问题: 1.搞清楚touch事件的传递(事件的响应链) 事件的响应(responder chain) 只有继承了UIResponder的类才能响应touch事件,从上图的响应者链可以看出,优先是最上层的 view响应事件,如果该view有视图控制器的话会是下一个响应者,否者就是该view的父视图,这样至上而下传递事件.直到单例UIWindow对 象,最后是单例UIApplication对象以终止,UIApplication的

iOS开发——网络编程OC篇&amp;(九)数据解析

数据解析 关于iOS开发的中数据解析的方法有两种JSON和XML,这里只做简单的介绍,会使用就可以了. JSON—— 关于JSON的解析经过很多爱好者的分析使用相同自带的还是最好的,不管是从使用的容易度还是性能方面 NSJSONSerialization 1 -(void)start 2 { 3 4 NSString* path = [[NSBundle mainBundle] pathForResource:@"Notes" ofType:@"json"]; 5