测试已测试 | ✓ |
Lang语言 | Obj-CObjective C |
许可协议 | MIT |
发布最新发布 | 2015年11月 |
由 Artem Yarulin 维护。
依赖 | |
GDataXML-HTML | = 1.3.0 |
React | > 0.10.0 |
React Native 兼容的 XML/HTML 解析器,支持 XPath
let xml = require('react-native').NativeModules.RNMXml
xml.queryXml('<doc a="V1">V2</doc>',
['/doc/@a', '/doc'],
results => results.map(nodes => console.log(nodes[0])))
// Output:
// V1
// V2
queryXml(xmlString,queries) -> results
queryHtml(htmlString,queries) -> results
xmlString
|htmlString
- xml 或 html 字符串queries
- 将对 xml 字符串执行的 xpath 字符串数组results
- 结果数组,如 queries.length == results.length
。每个结果也是一个数组let xml = require('react-native').NativeModules.RNMXml
xml.queryHtml('<html><div>a</div><div>b</div></html>',
['/html/body/div'],
results => console.log(results[0]))
//Output: ['a','b']
parseString(string,isHtml) -> parsedTree
其中 parsedTree 是一个字典(灵感来自 Clojure data.xml),具有以下结构
{"tag":"tagName",
"attrs:{"attrName":"attrValue"},
"content":[either text content or the same structure for each childs]}
请参阅 测试 获取更多信息
使用 Cocoapods
pod 'react-native-xml', '0.2.1'