IOS development uses XML to parse network data _ios

Source: Internet
Author: User

Foreword: This essay is about XML parsing.

Body:

1, the XML parsing method has 22 kinds:

DOM: A one-time load of XML data into memory for parsing, more suitable for parsing small files sax: Starting from the root element, in order an element of an element down to parse, more suitable for parsing large files

2, there are many kinds of XML parsing solution in iOS:

2-1. Third-Party framework:

LIBXML2: pure C language, default included in the iOS SDK, while supporting DOM and sax parsing

Gdataxml:dom approach, developed by Google, based on LIBXML2

2-2. Apple native

Nsxmlparser:sax method, easy to use

2-3, I based on Apple native Nsxmlparser packaged XML parsing tools

Hyxmlparser:sax Way of parsing, using more simple than nsxmlparser, more concise.

Download Address: Hyxmlparser

3, the choice of XML parsing method suggestions

Large files: Nsxmlparser or Hyxmlparser, LIBXML2 (but rarely)

Small files: gdataxml, Nsxmlparser or Hyxmlparser, LIBXML2

4, Nsxmlparser use examples:

The parsing process is three steps away:

  

  

  

5, about Hyxmlparser using the code sample diagram (after importing hyxmlparser after the following lines of code parsing finished, and easy to use):

The example shown here is the 3rd version of the XML parsing tool class downloaded from the Hyxmlparser xmlparser_3:

  

5-1, first copy the Hyxmlparse file tool class directly to your project:

  

5-2, and then use:

  

According to the actual demand, the method of the dictionary turn model may use mjextension instead of KVC most suitable.

If the reader is familiar with the original Apple Nsxmlparser, then to use my encapsulated good hyxmlparser, you will find that I encapsulated a good hyxmlparser is very simple and easy-to-use.

At the same time, it is suggested that the readers who have just learned XML parsing should master the Nsxmlparser analysis of Apple first, that is, the analytic process of the 4th introduction, and then learn to use my hyxmlparser.

6, simple to say that I encapsulated good hyxmlparser_3 of the realization of ideas.

6-1, the Apple native Nsxmlparser through the Proxy method Sax parsing XML is encapsulated in a common nsobject class.

6-2, in the agent resolution method, because the need to constantly create model objects, here I use the Nsobjectfromstring method, through the name of the class to create the class object, and then create the model object through the class object.

Thus the class name of the model object can be passed through the parameter NSString type, and the decoupling of the model object is realized, and the class of the model object required by the import is not required.

6-3, according to the actual demand, may need to mjextension dictionary to replace the limited function of Apple native KVC, so here with block to provide the external interface, so that the outside free choice dictionary to model the method.

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.