Gdataxmlnode -- XML Processing

Source: Internet
Author: User

Gdataxmlnode is a class set provided by Google for XML data processing. This set encapsulates the libxml2-DOM processing method, can read and write small or medium XML documents, and supports XPath syntax.

Obtain the gdataxmlnode. h and gdataxmlnode. M files, and import the files to the xcode project as follows:

1. Add the gdataxmlnode. h/m file to the project;

2. Add the "libxml2.dylib" Library to the project;

3. On the "build Settings" page of the project, locate the "header search path" and add "/usr/include/libxml2" to the path.

Add the "gdataxmlnode. H" file to any file. If the project can be compiled, the gdataxmlnode is successfully added.

Take generating a SOAP request as an example to show how to use this type of set.

The soap request to be generated:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.example.com/mobile/2010"><soap:Body><getProductAd/></soap:Body></soap:Envelope>

Code used:

     //SOAP Envelope    GDataXMLElement *envelope = [GDataXMLElement elementWithName:@"SOAP-ENV:Envelope"];        GDataXMLNode *soapNS = [GDataXMLNode namespaceWithName:@"SOAP-ENV" stringValue:@"http://schemas.xmlsoap.org/soap/envelope/"];    GDataXMLNode *xsiNS = [GDataXMLNode namespaceWithName:@"xsi" stringValue:@"http://www.w3.org/2001/XMLSchema-instance"];    GDataXMLNode *xsdNS = [GDataXMLNode namespaceWithName:@"xsd" stringValue:@"http://www.w3.org/2001/XMLSchema"];    GDataXMLNode *defaultNS = [GDataXMLNode namespaceWithName:@"" stringValue:@"http://www.example/mobile/2010"];        NSArray *namespaces = [NSArray arrayWithObjects:xsiNS, xsdNS, soapNS, defaultNS, nil];    [envelope setNamespaces:namespaces];        //SOAP Body    GDataXMLElement *body = [GDataXMLElement elementWithName:@"SOAP-ENV:Body"];        //SOAP Value    GDataXMLElement *value = [GDataXMLElement elementWithName:@"getProductAd"];    [body addChild:value];        [envelope addChild:body];        //SOAP Document    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithRootElement:envelope];    [doc setCharacterEncoding:@"utf-8"];        NSLog(@"doc = %@", [NSString stringWithCString:(const char *)[[doc XMLData] bytes] encoding:NSUTF8StringEncoding]);

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.