Haxe 与 XPath 有友谊吗?
Does Haxe have a friendship with XPath?
我需要通过它的 XPath 获取一些 XML 节点,我该怎么做?
我尝试使用这个库https://github.com/djcsdy/haxe-xpath, but something wrong https://github.com/djcsdy/haxe-xpath/issues/26
对于我的任务 xml-fast 不是好的解决方案,因为它看起来 "slightly worse" 比 XPath,我认为:
js(xpath):
xml_doc.get('//project/classpaths/class[@path="' + src_path + '"]')
haxe(xml-快):
(new Fast(xml_doc))).node.project.node.classpaths.nodes.class.filter(function (x:Fast) return x.has.path ? x.att.path == src_path : false)
谢谢
结果找到了两个库,都需要一些修复。
1. "Haxe XPath"
仅当将目录 "haxe-xpath/src/xpath" 克隆到您的源文件中时才能使用它(haxelib 存储库不包含此库)。
示例(删除第一个找到的元素):
package;
import xpath.XPathHx;
using Lambda;
class Main {
public static function main () {
var xml = Xml.parse("<a> <b> <c>qwe</c> <c>asd</c> </b> </a>");
trace(xml.toString());
var xpExpr = new XPathHx("//a/b/c"); // create new XPath expression object
var result = xpExpr.selectNodes(xml).array()[0]; // get first element from array of founded xml-nodes
result.parent.removeChild(result); // remove selected node from xml-tree
trace(xml.toString());
}
}
2. "xmlTools"
可以用haxelib安装:
haxelib install xmlTools
haxelib install composure
Some fix was needed for this library (in my task) and one nuance for xpath.
示例(删除第一个找到的元素):
package;
import xmlTools.XPath;
using Lambda;
class Main {
public static function main () {
var xml = Xml.parse("<a> <b> <c>qwe</c> <c>asd</c> </b> </a>");
trace(xml.toString());
var xpath = new XPath(); // create new XPath expression object
var result = xpath.resolve(xml, "*/a/b/c").array()[0]; // get first element from array of founded xml-nodes
result.parent.removeChild(result); // remove selected node from xml-tree
trace(xml.toString());
}
}
我需要通过它的 XPath 获取一些 XML 节点,我该怎么做?
我尝试使用这个库https://github.com/djcsdy/haxe-xpath, but something wrong https://github.com/djcsdy/haxe-xpath/issues/26
对于我的任务 xml-fast 不是好的解决方案,因为它看起来 "slightly worse" 比 XPath,我认为:
js(xpath):
xml_doc.get('//project/classpaths/class[@path="' + src_path + '"]')
haxe(xml-快):
(new Fast(xml_doc))).node.project.node.classpaths.nodes.class.filter(function (x:Fast) return x.has.path ? x.att.path == src_path : false)
谢谢
结果找到了两个库,都需要一些修复。
1. "Haxe XPath"
仅当将目录 "haxe-xpath/src/xpath" 克隆到您的源文件中时才能使用它(haxelib 存储库不包含此库)。
示例(删除第一个找到的元素):
package;
import xpath.XPathHx;
using Lambda;
class Main {
public static function main () {
var xml = Xml.parse("<a> <b> <c>qwe</c> <c>asd</c> </b> </a>");
trace(xml.toString());
var xpExpr = new XPathHx("//a/b/c"); // create new XPath expression object
var result = xpExpr.selectNodes(xml).array()[0]; // get first element from array of founded xml-nodes
result.parent.removeChild(result); // remove selected node from xml-tree
trace(xml.toString());
}
}
2. "xmlTools"
可以用haxelib安装:
haxelib install xmlTools
haxelib install composure
Some fix was needed for this library (in my task) and one nuance for xpath.
示例(删除第一个找到的元素):
package;
import xmlTools.XPath;
using Lambda;
class Main {
public static function main () {
var xml = Xml.parse("<a> <b> <c>qwe</c> <c>asd</c> </b> </a>");
trace(xml.toString());
var xpath = new XPath(); // create new XPath expression object
var result = xpath.resolve(xml, "*/a/b/c").array()[0]; // get first element from array of founded xml-nodes
result.parent.removeChild(result); // remove selected node from xml-tree
trace(xml.toString());
}
}