Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

iphone - How do I parse an NSString containing XML in Objective-C?

In my iPhone application, I have the following NSString:

NSString *myxml=@"<students>
    <student><name>Raju</name><age>25</age><address>abcd</address> 
    </student></students>";

How would I parse the XML content of this string?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Download: https://github.com/bcaccinolo/XML-to-NSDictionary

Then you simply do :

NSDictionary *dic = [XMLReader dictionaryForXMLString:myxml error:nil];

Result is a NSDictionary *dic with dictionaries, arrays and strings inside, depending of the XML:

{
    students =     {
        student =         {
            address = abcd;
            age = 25;
            name = Raju;
        };
    };
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...