Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在制作一个解析 nib/xib 文件并提供其所有子视图详细信息的 Cocoa 应用程序。使用 NSXMlDocument 解析文档非常酷,但在如何从 xml 结构中获取所需值时遇到问题。
这是结构:
我得到所有子节点但没有标签属性。如何获取属性?我在 XmlNode 上使用了 attributeKeys 属性,但它给了我空数组。是否有任何属性可以从结构中给我所需的值?
任何帮助,将不胜感激。
我只想从结构中获取标签的 id。
自己找到答案很好。获取 NSXmlNode 对象后,只需将其上传到 NSXmlElement 并发送消息 attributeForName 以获取值。
就我而言,
让 sc = subviews?.childCount
对于 var x = 0 ; x < sc ; x = x + 1 {
let each = subviews?.childAtIndex(x) as? NSXMLElement print(each?.attributeForName("id"))
}