GDataXMLNode——XML處理

來源:互聯網
上載者:User

GDataXMLNode是Google提供的用於XML資料處理的類集。該類集對libxml2-DOM處理方式進行了封裝,能對較小或中等的XML文檔進行讀寫操作且支援XPath文法。

獲得GDataXMLNode.h和GDataXMLNode.m檔案,進行如下操作將檔案匯入到Xcode的工程中:

    1. 將GDataXMLNode.h/m檔案添加到工程中;

    2. 向工程中增加“libxml2.dylib”庫;

    3. 在工程的“Build Settings”頁中找到“Header Search Path”項,添加“/usr/include/libxml2”到其路徑中

添加“GDataXMLNode.h”檔案到任一標頭檔中,如工程能編譯通過,則說明GDataXMLNode添加成功。

以產生一段SOAP請求為例,展示該類集的使用。

要產生的SOAP請求:

<?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>

使用的代碼:

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.