Previous ArticleArticle, It is good to convert XML into a tree and perform operations, but ignore the operation on the attributes on the XML node. Now let me modify it.CodeTo add attributes.
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. Modify the XML sample.
<? XML version = "1.0" encoding = "UTF-8"?> <Login> <loginresult id = "1"> true </loginresult> <logininfo> OK </logininfo> <lastlogin> </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"];