IOS development-XML parsing and pull-down refresh to pull and load more sharing, iosxml

Source: Internet
Author: User

IOS development-XML parsing and pull-down refresh to pull and load more sharing, iosxml
XML parsing for IOS development

  

1. XML format

<? Xml version = "1.0" encoding = "UTF-8"?> Indicates the XML file version. The internal text is encoded.

<Root> indicates the root node.

<CityName> Beijing </CityName> is a node. CityName indicates the end name and Beijing node value.

<Item key = "1" value = "A"> </Item> key = "1" is the node attribute, key attribute name, and "1" attribute value.

Note: The XML structure is understood as a layer-by-layer nested tree structure.

<? Xml version = "1.0" encoding = "UTF-8"?> <Root> <systemConfig> <CityName> Beijing </CityName> <CityCode> 201 </CityCode> <ParentCityCode> 0 </ParentCityCode> <areaCode> 010 </areaCode> <AgreementUrl> </AgreementUrl> <IntentionLevel> <Item key = "1" value = "A"> </Item> <Item key = "2" value = "B"> </ item> <Item key = "3" value = "C"> </Item> </IntentionLevel> <ComeChannel> <Item key = "1" value = "newspaper"> </Item> <Item key = "2" value = "magazine"> </Item> </ComeChannel> <BuyCarBudget> <Item key = "1" value = "40-50 thousand"> </Item> <Item key = "2" value = "50-60"> </Item> </BuyCarBudget> <IntentionColor> <Item key = "1" value =" red "> </Item> <Item key =" 2 "value =" yellow "> </Item> </IntentionColor> </systemConfig> </root>
2. How to use the open-source GData library for XML Parsing

Common XML parsing Methods

(1) unix-libxml2 C interface

(2) The XML parsing library provided by NSXMLParser UI is troublesome to use.

(3) GData development by google

2.1 Configuration

2.2 Use of GData
// 1. load and parse the XML file NSString * path = [[NSBundle mainBundle] pathForResource: @ "xml.txt" ofType: nil]; NSData * data = [[NSData alloc] initWithContentsOfFile: path]; // GDataXMLDocument indicates the XML Document Object // initWithData is initialized using NSData, that is, parsing GDataXMLDocument * doc = [[GDataXMLDocument alloc] initWithData: data options: 0 error: nil]; // 2. obtain the path of the specified node XPath // CityName:/root/systemConfig/CityName NSArray * array = [doc nodesForXPath: @ "/root/systemConfig/CityName" error: nil]; // CityName GDataXMLElement * element = [array firstObject]; NSLog (@ "name = % @ value = % @", element. name, element. stringValue); // 3. get the attribute NSArray * items = [doc nodesForXPath: @ "/root/systemConfig/ComeChannel/Item" error: nil]; GDataXMLElement * item = [items firstObject]; // obtain attributes. The attributes are represented by GDataXMLElement for (GDataXMLElement * attr in item. attributes) {NSLog (@ "a-name = % @ avalue = % @", attr. name, attr. stringValue);} // 4. get all nodes with the specified name (regardless of location) // XPath Syntax: // Item NSArray * allItem = [doc nodesForXPath: @ "// Item" error: nil]; for (GDataXMLElement * e in allItem) {NSLog (@ "name = % @", e. name);} // 5. obtain the attributes of all specified names (regardless of the node) // XPath Syntax: // @ value NSArray * allValue = [doc nodesForXPath: @ "// @ value" error: nil]; for (GDataXMLElement * e in allValue) {NSLog (@ "value = % @", e. stringValue);} // 6. traverse XML files layer by layer // obtain the root node GDataXMLElement * root = doc. rootElement; // obtain the subnode // root. children // obtain the number of subnodes // root. childCount // obtain the child node with the specified name // root elementsForName: <# (NSString *) #>

 

IOS development pull-down refresh and pull more

Common implementation methods of pull-down refresh

(1) UIRefreshControl

(2) EGOTableViewRefresh

(3) AH3DPullRefresh

(4) MJRefresh

(5) self-implementation

The specific refresh method will be discussed later!

Related Article

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.