IOS uses GDataXML-HTML to generate XML

Source: Internet
Author: User

IOS uses GDataXML-HTML to generate XML

XML classes that come with iOS versions can only be parsed and cannot be generated. Open-source library GDataXML-HTML not only supports XML parsing, but also supports generating XML.

1. Add GDataXML-HTML to the project.

All projects used by the author are hosted by Cocoapods. If you are not familiar with Cocoapods, refer to [cococoapods installation and use].

Add

pod 'GDataXML-HTML', '~> 1.1.0'

Run the following command to add the Library to the project:

pod update

2. Add the libxml header file location for the project

In the project configuration, add "Header Search Paths:

${SDK_ROOT}/usr/include/libxml2






3. Use GDataXML-HTML in the project

// Create a Tag element GDataXMLElement * element = [GDataXMLNode elementWithName: @ "user" stringValue: @ "will"]; // create an attribute GDataXMLElement * attribute = [GDataXMLNode attributeWithName: @ "a" stringValue: @ "B"]; // create a root tag GDataXMLElement * rootElement = [GDataXMLNode elementWithName: @ "root"]; // Add the tag and attribute to the root tag [rootElement addChild: element]; [rootElement addAttribute: attribute]; // generate the xml file content GDataXMLDocument * xmlDoc = [[GDataXMLDocument alloc] initWithRootElement: rootElement]; NSData * data = [xmlDoc XMLData]; NSString * xmlString = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding]; NSLog (@ "% @", xmlString );

The NSlog output content is:

 
 
  
   will
  
 




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.