IOS developmentZhihuiXMLConvertTreeThis is the content to be introduced in this article. Continue to explain how to convert XML into a tree in iOS development.XmlConvertTree, And perform operations, but ignoreXmlNow let me modify the code to add the attribute.
1. Add an attributeDict of the NSDictionary type to the treenode to store attributes. The Code is as follows:
- NSDictionary * attributeDict;
2. You can obtain the attribute list in parser: didStartElement: method, and add the following code in it.
- leaf.attributeDict = [[NSDictionary alloc] initWithDictionary:attributeDict];
3. Modification exampleXml.
- <?xml version="1.0" encoding="UTF-8"?>
- <Login>
- <LoginResult id="1">True</LoginResult>
- <LoginInfo>OK</LoginInfo>
- <LastLogin>2011-05-09 12:20</LastLogin>
- <Right>
- <A>1</A>
- <B>1</B>
- <C>0</C>
- </Right>
- </Login>
4. Obtain the value of the property id.
- TreeNode * resultTreeNode = [node objectForKey:@"LoginResult"];
- NSString *result = [resultTreeNode.attributeDict objectForKey:@"id"];
Summary:IOS developmentZhihuiXMLI hope this article will be helpful to you.