英文:
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对象中,以下的entry在CSV格式中很难表示:
<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.
<?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>
Out of above XML object below entry is something hard to represent in the CSV format
       <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>
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
以下是翻译好的内容:
- 
参考以下链接:
 - 
创建一个Diff实例来比较两个XML文件:
 
    Diff xmlDiff = new Diff(source, target); 
- 获取两个XML文件之间的详细差异:
 
    DetailedDiff detailXmlDiff = new DetailedDiff(xmlDiff);
希望这有所帮助。
英文:
Have a look at these for reference..
- https://javarevisited.blogspot.com/2017/04/how-to-compare-two-xml-files-in-java.htm
 - 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论