An application has read some infos in a particular XML file. I'd like to add another option, here is the description:
Here is an example of my XML type file:
I would like to count that video & gt; element & lt; Video & gt; is in the node.
For example, 2 How can I do this? Using NSXMLDocument?
I want to write results in a textfield.
Example:
There are 5 videos in the XML file
If someone can help, then it would be good!
Thanks in advance
Miska
(And sorry for my poor english, I'm French: p)
Something like this should be done. I'll leave you handling the error.
NSData * Data = [NSData dataWithContentsOfFile: pathToYourXMLFile]; NSError * Error = Zero; NSXML Document * Document = [[NSXML Document Alok] initWithData: Data Option: 0 Error: and Error]; If (! Error) {NSXMLElement * rootElement = [document root element]; NSUIntiger calculation = [[root element nodes forexpath: @ "// video" error: & amp; Error] count]; If (! Error) {NSString * videosCount = zero; If (calculation == 0) VideoCount = [NSString stringWithFormat: @ "There is no video in XML file."]; And if (calculation == 1) VideoCount = [NSString stringWithFormat: @ "There is 1 video in XML file."]; Other videocount = [NSString stringWithFormat: @ "There are% d video in XML file.", Counting]; [MyTextField setStringValue: VideoCount]; }} [Document release]
Comments
Post a Comment