Introduction:
In iOS, you often encounter XML files or strings converted into nsdictionary;
Demand:
The Web service side requests and returns the data format to be XML; The control must be dynamically generated based on the parsing XML file; The form may be filled in and temporarily saved; a form is a <a/> contains content, the form as long as the id,name on the line;
If the form fills in values, add value in <a/>.
<a>
<f>1</f> <!--id-->
<n>2ewew</n> <!--name--
<q>2ewew</q> <!--Verification--
</a>
<a/>
..................
Reference Https://codeload.github.com/nicklockwood/XMLDictionary/zip/master
and find the innertext in the xmldictionary.m file and modify the following:
-(ID) innerText
{
ID text = Self[xmldictionarytextkey];
if ([Text Iskindofclass:[nsarray class]])
{
return [text componentsjoinedbystring:@ "\ n"];
}
Else
{
Determine if value is empty
if ([(NSString *) text length]==0) {
return @ "";
}else
return text;
}
}
Whether 1, <a><f><t><t/><f/><a> or 2, <a><f><t>4424<t/> after the above modification <f/><a/>
Both XML and Nsdictionary can be converted to each other;
Otherwise
The following conditions occur:
<?xml version= "1.0" encoding= "Utf-8"?><transactions><transaction>
1.
Dictionary: {
"__name" = transactions;
}
xmlstring==========
<transactions/>======
After modification
Dictionary: {
"__name" = transactions;
Transaction = {
Head = "";
};
}
mlstring==========
<transactions><transaction>
</transaction>
</transactions>======
Reference Https://codeload.github.com/nicklockwood/XMLDictionary/zip/master
Source code Address:
IOS XML and Nsdictionary convert each other