IOS XML and Nsdictionary convert each other

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.