iOS development has always been the use of Jason to parse the most recent company is the use of XML parsing for a long time have not used a little strange today to carefully describe the XML parsing! When it comes to XML parsing, it's important to describe two concepts, a DOM called sax sax, which is a simple API-for-XML abbreviation, and it's not a standard that is made by the official, it's a "folk" fact standard. In fact, it is a community-based discussion product. However, the application of Sax in XML is no less than DOM, and almost all XML parsers will support it. Sax is a lightweight method that is event-driven, that is, it does not need to read the entire document, and the document's read-in process is the SAX parsing process. The so-called event-driven, refers to a method based on the callback (callback) mechanism of program operation. There is Dom Dom parsing is a mouthful of food into memory, we need to read into the entire XML document, and then in memory to create a DOM tree, the DOM tree to generate each node object, when the document is relatively small, this does not cause any problems, but once the document is large, Working with the DOM becomes quite time-consuming and laborious. In particular, its memory needs, it will be multiplied, so that in some applications to use the DOM is a very bad thing, so to parse the big things to use sax, but now the device performance is getting better, the sense of difference should not be too big, of course, just I personally think, do the development, Be sure to put the user's experience in the first place, so it is best to follow the appropriate method to solve it, good, nonsense less say on the code!
Gdataxmldocument *doc = [[Gdataxmldocument alloc] initwithdata:responseobject options:0Error:nil]; //get the root element of the document--Doc elementGdataxmlelement *root =doc.rootelement; //get the BODY element inside the root elementNsarray *elements = [Root elementsforname:@"Body"]; //iterate through all the body elements for(Gdataxmlelement *videoelementinchelements) {Nsarray*arr=[videoelement Elementsforname:@"mi_user_addresss"]; NSLog (@"%ld", Arr.count); for(Gdataxmlelement *ementincharr) {Nsarray*arr=[ement Elementsforname:@"mi_user_address"]; for(Gdataxmlelement *elementincharr) { //Take out the value of each node elementSelf.adress =[[Wyadress alloc] init]; Gdataxmlelement*address=[[element Elementsforname:@"Address"]objectatindex:0]; Self.adress.address=[Address stringvalue];
// This is the value that is taken from the attributes in the element self. id = [Element attributeforname:@ "ID"].stringvalue.intvalue;
Incidentally, you can also use this method to take
// get the path first and then get the node NSString *path=@ "/doc/body"; // 2. Get the body node Gdataxmlelement *bodyelement=[rootelement Nodesforxpath:path error:nil][0];
XML parsing Gdata