使用 ruby Nokogiri 我有一个
Nokogiri::XML::Node
对象(ConstituencyXMLNode 继承自 Nokogiri::XML::Node
),它是一个像这样的树对象:
#(ConstituencyXMLNode:0xc3c8 {
name = "PP",
children = [
#(ConstituencyXMLNode:0xc3dc { name = "IN", children = [ #(Text "out")] }),
#(ConstituencyXMLNode:0xc3f0 {
name = "PP",
children = [
#(ConstituencyXMLNode:0xc404 { name = "IN", children = [ #(Text "of")] }),
#(ConstituencyXMLNode:0xc418 {
name = "NP",
children = [
#(ConstituencyXMLNode:0xc42c { name = "JJ", children = [ #(Text "non-living")] }),
#(ConstituencyXMLNode:0xc440 { name = "NNS", children = [ #(Text "resources")] })]
})]
})]
})
我们会叫它
pp_leaf
我想比较并查看此节点的部分是否包含在其他部分 Nokogiri::XML::Node:
中#(ConstituencyXMLNode:0xc3f0 {
name = "PP",
children = [
#(ConstituencyXMLNode:0xc404 { name = "IN", children = [ #(Text "of")] }),
#(ConstituencyXMLNode:0xc418 {
name = "NP",
children = [
#(ConstituencyXMLNode:0xc42c { name = "JJ", children = [ #(Text "non-living")] }),
#(ConstituencyXMLNode:0xc440 { name = "NNS", children = [ #(Text "resources")] })]
})]
})
我们称这个节点为
current_leaf
.
Nokogiri::XML::NodeSet
似乎有我正在寻找的比较工具,但我不确定如何将Nokogiri::XML::Node
转换为Nokogiri::XML::NodeSet
。如果一组包含另一组,Nokogiri::XML::Node
上的所有运算符似乎都没有我需要匹配的比较运算符。
有什么想法吗?