2016-05-30 4 views
2

XMLノードをXPathで取得する必要がありますが、どうすればできますか?HaxeはXPathと友好関係にありますか?

私はこのライブラリhttps://github.com/djcsdy/haxe-xpathを使用しようとしましたが、何か間違ったhttps://github.com/djcsdy/haxe-xpath/issues/26

、私の仕事のためのXML-速いが、それは、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) 

ありがとう

+0

"haXeの-のxpathは、" いくつかの小さな修正https://github.com/djcsdy/haxe-xpath/issues/26ました –

答えて

2

結果として2つのライブラリが見つかりましたが、いずれもいくつかの修正が必要です。それは場合にのみ使用することができます

1."Haxe XPath"

あなたのソース(haxelibレポはこのライブラリが含まれていない)にクローンディレクトリ "haXeの-のxpath/SRC/XPathは、"。 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)と1 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()); 
    } 
} 
関連する問題