如何检查一个文件中的XMLNode是否是另一个文件中XMLNode的子集 [英] How to check if XMLNode in one file is a subset of an XMLNode in another file

查看:61
本文介绍了如何检查一个文件中的XMLNode是否是另一个文件中XMLNode的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个XML文件,(文件A和文件B)

I have two XML files, (file A and file B)

文件A有10个主节点,每个主节点有5个子节点,文件2有10个主节点节点,但每个主节点有2个子节点。

File A has 10 main nodes with 5 subnodes in each main node, file 2 has same 10 main nodes but with 2 subnodes in each main node.

我需要将文件A中的每个主节点与文件B中对应的主节点进行比较,并检查:

I need to Compare each main node in file A with corresponding main node in file B and check that:

a。文件B中该主节点的子节点是文件A中相应主节点的子节点的子集。

a. subnodes of that main node in file B is a subset of subnodes of corresponding main node in file A.

b。对于两个文件中的每个公共子节点,内容(innertext,value等)相等。

b. for each common subnode in both files, the content(innertext, value, etc) is equal.

注意:

xml中有多个层次结构级别,即node-> subnode-> subsubnode-> subsubsubnode等。

there are multiple hierarchy levels in the xml i.e node->subnode->subsubnode->subsubsubnode, etc.

必须满足所有节点的条件/子节点

The condition must be satisfied for all nodes/subnodes

推荐答案

嗯,没有内置的方法可以做到这一点。 你需要一个"CompareSubtrees"。函数 - 可能是递归的 - 枚举节点的子节点并确保它们是相同的。 然后,你需要一个"CheckSubset"。函数
非常相似,但不关心A中是否有额外的节点。

Well, there's no built-in way to do that.  You'll need a "CompareSubtrees" function -- probably recursive -- that enumerates the subnodes of the nodes and ensures they are the same.  Then, you'll need a "CheckSubset" function that is quite similar, but doesn't care if there are extra nodes in A.

因此,你将使用两个顶级调用CheckSubset,并且每个匹配节点,调用CompareSubtree。

So, you'll call CheckSubset with the two top-levels, and with each matching node, call CompareSubtree.

这听起来很简单,但有点棘手。

It sounds simple, but it's a bit tricky.


这篇关于如何检查一个文件中的XMLNode是否是另一个文件中XMLNode的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆