iOS learning: Common third-party libraries (Gdataxmlnode:xml parsing library)

Source: Internet
Author: User

 iOS Learning: Common third-party libraries (Gdataxmlnode:xml parsing library)Category: iOS development learning 2013-05-30 09:45 4443 People read reviews (0) favorite reports Iosxmlgdataxmlnode Gdataxmlnode Description Gdataxmlnode is a set of classes provided by Google for XML data processing. This class set encapsulates libxml2--dom processing, reads and writes to smaller or medium XML documents, and supports XPath syntax. How to use: 1, get the gdataxmlnode.h/m file, add the gdataxmlnode.h/m file to the Project 2, adding "Libxml2.dylib" Library 3 to the project, find "Hea" in the project "Build Settings" page Der Search Path "entry, add/USR/INCLUDE/LIBXML2" to the path 4, add "GDataXMLNode.h" file to the head file, if the project can be compiled through, then Gdataxmlnode add success Two, Gdataxmlnode Sample Example: [HTML]View Plaincopy
    1. <root>
    2. <name value="WUSJ"/>
    3. <age>24</age>
    4. </root>
Parsing this XML file [CPP]View Plaincopy
  1. NSString *xmlpath = [[Nsbundlemainbundle] pathforresource:@"test" oftype:@"xml"];
  2. NSString *xmlstring = [Nsstringstringwithcontentsoffile:xmlpath Encoding:NSUTF8StringEncodingerror:nil];
  3. Gdataxmldocument *xmldoc = [[Gdataxmldocumentalloc] initwithxmlstring:xmlstring Options:0error:nil];
  4. Gdataxmlelement *xmlele = [xmldoc rootelement];
  5. Nsarray *array = [Xmlele children];
  6. NSLog (@"Count:%d", [array Count]);
  7. For (int i = 0; i < [array count]; i++) {
  8. Gdataxmlelement *ele = [array objectatindex:i];
  9. //According to the label name
  10. if ([[[Ele name] isequaltostring:@"name"]) {
  11. //Read the attribute inside the tag
  12. NSLog (@"name-to-%@", [[Ele attributeforname:@"value"] stringvalue]);
  13. } Else {
  14. //Direct-read string between tags
  15. NSLog (@ "age-and%@", [Ele stringvalue]);
  16. }
  17. }

Operation Result: Third, Gdataxmlnode method summary The final data readout is read in the Gdataxmlelement object, the following methods are Gdataxmlelement class Method 1, name method, take the label name e.g The name tag names "Name" 2, Attributeforname: Take the attribute node StringValue can be taken to the property value e.g name tag of the Value property 3, StringValue: Take the string value between tags e.g: Age of 24

iOS learning: Common third-party libraries (Gdataxmlnode:xml parsing library)

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.