使用xpath时如何获取CXMLElement
当 xpath 查询文档时,有没有办法获取 CXMLElement
? - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
返回的 XCMLNode
项不包含属性函数。
有没有办法直接获取元素或将节点转换为元素?
谢谢
Is there a way to get a CXMLElement
back when xpath querying a document? The XCMLNode
item returned by the - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;
doesn't contain the attributes functions.
Is there a way to either directly get an element or convert the node to an element?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以强制转换它,但请务必先检查类型:
You can cast it, but be sure to check the type first:
AFAIR CXMLElement 是 CXMLNode 的子类。如果您确定 xpath 将返回 CXMLElements,则只需将 CXMLNode 转换为 CXMLElement。在其他情况下,您应该检查节点类型然后进行强制转换。
来自 touchXML 文档:
AFAIR CXMLElement is a subclass of the CXMLNode. If you are sure that the xpath will return CXMLElements, then just cast CXMLNode to CXMLElement. In other case you should check node type and then cast.
From touchXML documention: