java - 根据本地 XML 文件验证 XML 文件的最佳方法是什么?
问题描述
我正在开发一些测试框架。我想用本地数据验证极其复杂的 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>
或持有list of maps
等的 XML 数据。
是否有任何可用的框架、库可以验证如此复杂的 XML 数据?
解决方案
看看这些以供参考..
- https://javarevisited.blogspot.com/2017/04/how-to-compare-two-xml-files-in-java.htm
- 在 Java 中比较 2 个 XML 文档的最佳方法
//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);
希望这可以帮助。
推荐阅读
- angular - Angular 11 的问题(从 8 到 11 的角度升级后)
- c# - 按住键移动而不是发送垃圾邮件
- git - 带有 git add 的单个命令以忽略未跟踪的文件
- android - 对从 JSON 解析获得的对象执行 while 循环收到错误:org.json.JSONException: Index 3 out of range [0..3), android studio
- flutter - 如何在android studio中禁用外部点击时最小化ios模拟器?
- google-api - Google V3 API - 文件上传到共享驱动器
- tensorflow - Tensorflow2 目标检测训练 | 使测试结果相同
- javascript - 如何在 html 中上传文档时添加加载符号
- cyber-ark - 使用可信证书从 CyberArk 检索密码
- javascript - 如何在 dygraph 的范围选择器中设置选定范围