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
- <root>
- <name value="WUSJ"/>
- <age>24</age>
- </root>
Parsing this XML file
[CPP]View Plaincopy
- NSString *xmlpath = [[Nsbundlemainbundle] pathforresource:@"test" oftype:@"xml"];
- NSString *xmlstring = [Nsstringstringwithcontentsoffile:xmlpath Encoding:NSUTF8StringEncodingerror:nil];
- Gdataxmldocument *xmldoc = [[Gdataxmldocumentalloc] initwithxmlstring:xmlstring Options:0error:nil];
- Gdataxmlelement *xmlele = [xmldoc rootelement];
- Nsarray *array = [Xmlele children];
- NSLog (@"Count:%d", [array Count]);
- For (int i = 0; i < [array count]; i++) {
- Gdataxmlelement *ele = [array objectatindex:i];
- //According to the label name
- if ([[[Ele name] isequaltostring:@"name"]) {
- //Read the attribute inside the tag
- NSLog (@"name-to-%@", [[Ele attributeforname:@"value"] stringvalue]);
- } Else {
- //Direct-read string between tags
- NSLog (@ "age-and%@", [Ele stringvalue]);
- }
- }
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)