This is an XML data, the same as the JSON data content of the previous article, the Previous one is in JSON format , This article uses the XML format of data
The code for the above article in this article is based on modifications :
1> the data form into XML data , so modify the path to the file
2> because the data format is different, so the parsing method first uses the GData method to parse the XML document
Requirements : parse the data in this XML document and show it through TableView , The requirements of the previous article are the same , But the data is different from the parsing method
Here is only the parsing of This code, that is, JSON parsing 2 articles in the Code section , 61--89 line section , the beginning of the partial modification of the file path .
Using the GD ATA Framework to resolve Xml,dom parsing : load the file at once memory resolution , suitable for small files , large files can cause memory spikes , the operation is relatively simple .
The following is a partial code for parsing:
DOM parsing process :
Our goal : to get the attribute values in the XML with each of the elements in the element , which is the data we need
get the attribute value assignment to the corresponding property of our model , and then complete the data modeling process after the assignment .
Note the Image property in the view XML is an address that the program runs successfully on tableView
is the picture , These pictures are set up in tableViewCell , through the SDWebimage This frame
Key points in the code of the data modeled several assignments, the data data to assign to the model , the model to get the information to re-address work
The 164 line passes the model. Image This property creates a URL path , SDWebimage The path to find the image to set .
Click the cell to play the video is implemented here
The 113 line passes the model. The URL creates a path , and the line jumps through this path .
The remaining pass attribute is directly taken to the inside of the attribute . such as name. A property that is assigned directly to the cell, such as length , is an assignment operation
Images and videos , in addition to assigning values and addressing operations , to achieve data resolution .
after the client sends the request to the server , the data is successfully obtained , and there is no error , which means that we have the data of the XML file .
DOM parsing : Get everything inside the document once and load it into memory for parsing
First set gdataxmldocument to create a gdataxmldocument object with the data you get
This object will parse the data further based on his root element , so the root element will parse the error if there are multiple
According to the XML data format above, we can see that there are many child elements with elements , and the attributes in the child elements are the data we need.
Take out all the child elements of the root element into the array , and then iterate through the array to take each of the sub-elements . Through
This method :attributeforname get the content inside , and then assign the value to the model .
Dom parsing instructions are complete, the following is the sdwebimage use the relevant attention points
###########
Gdata is a Google development framework, the bottom is the C language, because the development of many years so there is MRC code, our environment is arc.
The first thing to import is the header file:
#import "GDataXMLNode.h"
Will find an error:
1> compiler could not find path: manual gap su Compiler the path to the file
2> change this file to MRC mode
Parsing of XML data parsing DOM method