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]);