Xml Parsing using NSXml Document

124 Views Asked by At

I am making a Cocoa app that parses nib/xib files and gives all its subviews details.Parsing the document is pretty cool with the NSXMlDocument but having a problem at one place to how to get the desired value from the xml structure.

This is the structure:

getting all the nodes like rect, animations,font descriptions ect..,I am getting all the child nodes but not the label attributes.How to get the attributes? i used attributeKeys property on the XmlNode but its giving me empty array.Is there any property that gives me the desired value from the structure?

Any help would be appreciated.

I just want to get the id of the Label from the structure.

1

There are 1 best solutions below

0
On

Its been good to find out the answer myself.After getting the NSXmlNode object just upcast it to NSXmlElement and send message attributeForName to get the value.

In my case,

let sc = subviews?.childCount

for var x = 0 ; x < sc ; x = x + 1 {

let each = subviews?.childAtIndex(x) as? NSXMLElement

print(each?.attributeForName("id"))

}