)nsxmlparserdelegate
)//獲取路徑
nsstring
*path = [[
nsbundle
mainbundle
]pathforresource
:@"students"
oftype
:@"xml"];
nsdata
*data = [
nsdata
datawithcontentsoffile
:path];
nsxmlparser
*student = [[
nsxmlparser
alloc
]initwithdata
:data];
student.
delegate
=self;
[student
parse];
#pragma nsxml
**方法
-(void
)parserdidstartdocument:(
nsxmlparser
*)parser
-(void
)parserdidenddocument:(
nsxmlparser
*)parser
//一直迴圈呼叫這個三個**方法
//解析開始標籤
-(void
)parser:(
nsxmlparser
*)parser didstartelement:(
nonnull
nsstring
*)elementname namespaceuri:(
nullable
nsstring
*)namespaceuri qualifiedname:(
nullable
nsstring
*)qname attributes:(
nonnull
nsdictionary
<
nsstring
*,nsstring
*> *)attributedict
//結束標籤
-(void
)parser:(
nsxmlparser
*)parser didendelement:(
nonnull
nsstring
*)elementname namespaceuri:(
nullable
nsstring
*)namespaceuri qualifiedname:(
nullable
nsstring
*)qname
//獲取標籤內容
-(void
)parser:(
nsxmlparser
*)parser foundcharacters:(
nonnull
nsstring
*)string
//錯誤資訊
提示**
-(void
)parser:(
nsxmlparser
*)parser parseerroroccurred:(
nonnull
nserror
*)parseerror
撒旦 2.1 先獲取資料
//獲取路徑位址
nsstring
*path = [[
nsbundle
mainbundle
]pathforresource
:@"students"
oftype
:@"xml"];
nsdata
*data = [
nsdata
datawithcontentsoffile
:path];
gdataxmldocument
*document = [[
gdataxmldocument
alloc
]initwithdata
:data
options
:nil
error
:nil];
//獲取根節點
gdataxmlelement
*rootelement = [document
rootelement];
//獲取子節點
nsarray
*childarray = [rootelement
elementsforname
:@"student"];
//建立儲存結果的陣列
nsmutablearray
*array = [
nsmutablearray
array];
for(gdataxmlelement
*chlidelement
inchildarray)
nslog
(@"%@"
,array);
OC基礎 XML的解析方式
dom 建立xml解析器 nsxmlparser parser nsxmlparser alloc initwithdata data 設定 parser.delegate self 開始解析xml parse方法是阻塞式的 parser parse 解析到某個元素的結尾 比如解析 void par...
建立xml檔案 解析xml檔案
import codecs import xml.dom.minidom doc xml.dom.minidom.document print doc root doc.createelement booklist print u 新增的xml標籤為 root.tagname root.setatt...
解析XML檔案
sax解析xml 得到saxparse ctory saxparse ctory saxparse ctory saxparse ctory.newinstance 得到saxparser saxparser saxparser saxparse ctory.newsaxparser 得到xmlre...