XML parsing dom (2)

Source: Internet
Author: User
  1. Retrieve resolution file path
    Nsstring * xmlpath = [[nsbundle mainbundle] pathforresource: @ "person" oftype: @ "XML"];

2. Initialize an XML string
Nsstring * xmlstr = [nsstring stringwithcontentsoffile: xmlpath encoding: nsutf8stringencoding error: Nil];


3. initialize a gdataxmldocument object, because all the content during parsing is obtained from this object (so you need to put the content to be parsed into this object)
Gdataxmldocument * Document = [[gdataxmldocument alloc] initwithxmlstring: xmlstr options: 0 error: Nil];

If XPath is given a relative path, such as // name. If it can reach the name, the name can be obtained.
Retrieve all Name nodes
Nsarray * nameelement = [document nodesforxpath: @ "// name" error: Nil];
Get all gender nodes
Nsarray * genderelement = [document nodesforxpath: @ "// gender" error: Nil];

Retrieve each node cyclically

For (INT I = 0; I <3; I ++ ){
Gdataxmlelement * nameele = nameelement [I];
Gdataxmlelement * genderele = genderelement [I];

Take the string in the node attribute
Nsstring * A = [[nameele attributeforname: @ "name"] stringvalue];


Get node string
Nsstring * name = [nameele stringvalue];
Nslog (@ "AAA ddddd % @", );
}


XML parsing dom (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.