什么是验证本地 XML 文件与本地 XML 文件相匹配的最佳方法?

huangapple go评论75阅读模式
英文:

What's the best way to validate an XML file against local XML file?

问题

我正在开发一些测试框架。我打算使用本地数据来验证极其复杂的XML响应。

我考虑将本地数据保存为CSV格式,并实现了一些验证,但我发现这些框架的局限性,即无法验证复杂的数据,例如:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE ResourceObject PUBLIC "abc_corp.dtd" "abc_corp.dtd">
<ResourceObject displayName="abcd" identity="pqr" objectType="account" uuid="123456">
  <Attributes>
    <Map>
      <entry key="memberOf"/>
      <entry key="objectClass">
        <value>
          <List>
            <String>top</String>
            <String>person</String>
            <String>organizationalPerson</String>
            <String>user</String>
          </List>
        </value>
      </entry>
      <entry key="objectSid" value="S-1-5"/>
      <entry key="objectType" value="user"/>
        <value>
          <List>
            <Permission rights="allow:elasticmapreduce:Describe*" target="*"/>
            <Permission rights="allow:elasticmapreduce:List*" target="*"/>
            <Permission rights="allow:elasticmapreduce:ViewEventsFromAllClustersInConsole" target="*"/>
            <Permission rights="allow:s3:GetObject" target="*"/>
            <Permission rights="allow:s3:ListAllMyBuckets" target="*"/>
            <Permission rights="allow:s3:ListBucket" target="*"/>
            <Permission rights="allow:sdb:Select" target="*"/>
            <Permission rights="allow:cloudwatch:GetMetricStatistics" target="*"/>
          </List>
        </value>
      </entry>
    </Map>
  </Attributes>
</ResourceObject>

在上述XML对象中,以下的entryCSV格式中很难表示:

<entry key="objectType" value="user"/>
  <value>
    <List>
      <Permission rights="allow:elasticmapreduce:Describe*" target="*"/>
      <Permission rights="allow:elasticmapreduce:List*" target="*"/>
      <Permission rights="allow:elasticmapreduce:ViewEventsFromAllClustersInConsole" target="*"/>
      <Permission rights="allow:s3:GetObject" target="*"/>
      <Permission rights="allow:s3:ListAllMyBuckets" target="*"/>
      <Permission rights="allow:s3:ListBucket" target="*"/>
      <Permission rights="allow:sdb:Select" target="*"/>
      <Permission rights="allow:cloudwatch:GetMetricStatistics" target="*"/>
    </List>
  </value>
</entry>

或者包含列表等的XML数据。

是否有任何可用的框架或库可以验证这种复杂的XML数据?

英文:

I'm developing some test framework. I suppose to validate the extremely complex XML responses with local data.

I thought to have local data in the CSV format and achieved some validation but I found the limitation of this frameworks that I can't validate complex data e.g.

&lt;?xml version=&#39;1.0&#39; encoding=&#39;UTF-8&#39;?&gt;
 &lt;!DOCTYPE ResourceObject PUBLIC &quot;abc_corp.dtd&quot; &quot;abc_corp.dtd&quot;&gt;
 &lt;ResourceObject displayName=&quot;abcd&quot; identity=&quot;pqr&quot; objectType=&quot;account&quot; uuid=&quot;123456&quot;&gt;
   &lt;Attributes&gt;
     &lt;Map&gt;
       &lt;entry key=&quot;memberOf&quot;/&gt;
       &lt;entry key=&quot;objectClass&quot;&gt;
         &lt;value&gt;
           &lt;List&gt;
             &lt;String&gt;top&lt;/String&gt;
             &lt;String&gt;person&lt;/String&gt;
             &lt;String&gt;organizationalPerson&lt;/String&gt;
             &lt;String&gt;user&lt;/String&gt;
           &lt;/List&gt;
         &lt;/value&gt;
       &lt;/entry&gt;
       &lt;entry key=&quot;objectSid&quot; value=&quot;S-1-5&quot;/&gt;
       &lt;entry key=&quot;objectType&quot; value=&quot;user&quot;/&gt;
          &lt;value&gt;
           &lt;List&gt;
             &lt;Permission rights=&quot;allow:elasticmapreduce:Describe*&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:elasticmapreduce:List*&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:elasticmapreduce:ViewEventsFromAllClustersInConsole&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:s3:GetObject&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:s3:ListAllMyBuckets&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:s3:ListBucket&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:sdb:Select&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:cloudwatch:GetMetricStatistics&quot; target=&quot;*&quot;/&gt;
           &lt;/List&gt;
         &lt;/value&gt;
       &lt;/entry&gt;
     &lt;/Map&gt;
   &lt;/Attributes&gt;
 &lt;/ResourceObject&gt;

Out of above XML object below entry is something hard to represent in the CSV format

       &lt;entry key=&quot;objectType&quot; value=&quot;user&quot;/&gt;
          &lt;value&gt;
           &lt;List&gt;
             &lt;Permission rights=&quot;allow:elasticmapreduce:Describe*&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:elasticmapreduce:List*&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:elasticmapreduce:ViewEventsFromAllClustersInConsole&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:s3:GetObject&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:s3:ListAllMyBuckets&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:s3:ListBucket&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:sdb:Select&quot; target=&quot;*&quot;/&gt;
             &lt;Permission rights=&quot;allow:cloudwatch:GetMetricStatistics&quot; target=&quot;*&quot;/&gt;
           &lt;/List&gt;
         &lt;/value&gt;
       &lt;/entry&gt;

Or XML data which hold list of maps etc.

Is there any framework, library available which could validate such a complex XML data?

答案1

得分: 1

以下是翻译好的内容:

  1. 参考以下链接:

  2. 创建一个Diff实例来比较两个XML文件:

    Diff xmlDiff = new Diff(source, target); 
  1. 获取两个XML文件之间的详细差异:
    DetailedDiff detailXmlDiff = new DetailedDiff(xmlDiff);

希望这有所帮助。

英文:

Have a look at these for reference..

  1. https://javarevisited.blogspot.com/2017/04/how-to-compare-two-xml-files-in-java.htm
  2. https://stackoverflow.com/questions/141993/best-way-to-compare-2-xml-documents-in-java
    //creating Diff instance to compare two XML files 
    Diff xmlDiff = new Diff(source, target); 
    
    //for getting detailed differences between two xml files 
    DetailedDiff detailXmlDiff = new DetailedDiff(xmlDiff);

Hope this helps.

huangapple
  • 本文由 发表于 2020年4月9日 15:57:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/61116430.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定