gpt4 book ai didi

xml - Haxe与XPath有友谊吗?

转载 作者:行者123 更新时间:2023-12-03 16:16:18 26 4
gpt4 key购买 nike

我需要通过XPath获取一些XML节点,我该怎么做?

我尝试使用此库https://github.com/djcsdy/haxe-xpath,但https://github.com/djcsdy/haxe-xpath/issues/26出错

对于我的任务xml-fast并不是一个很好的解决方案,因为它看起来比XPath“稍差”,我认为:

js(xpath):

xml_doc.get('//project/classpaths/class[@path="' + src_path + '"]')


haxe(xml-fast):

(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存储库不包含此库)时,才可以使用它。

该库需要一些修复:thisthis

示例(删除第一个找到的元素):

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)和一个 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());
}
}

关于xml - Haxe与XPath有友谊吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37528220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com