【发布时间】:2017-02-07 09:25:40
【问题描述】:
我必须比较 2 个 xml 字符串。
实际
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xml:base="http://localhost:49531/ODataV2.svc/ODataV2.svc/">
<content type="application/xml">
<m:properties>
<d:ID>2000</d:ID>
<d:ReleaseDate>1992-01-01T00:00:00</d:ReleaseDate>
<d:Rating>4</d:Rating>
<d:Price>2.5</d:Price>
</m:properties>
</content>
</entry>
预期
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xml:base="http://localhost:55615/ODataV2.svc/ODataV2.svc/">
<content type="application/xml">
<m:properties>
<d:ID>2000</d:ID>
<d:ReleaseDate>1992-01-01T00:00:00</d:ReleaseDate>
<d:Rating>4</d:Rating>
<d:Price>2.5</d:Price>
</m:properties>
</content>
</entry>
以下代码失败,因为属性 xml:base 中的端口号在根节点中不同。
XMLAssert.assertXMLEqual(Actual, Expected);
预期的属性值 'http://localhost:55615/ODataV2.svc/ODataV2.svc/' 但是是 'http://localhost:49531/ODataV2.svc/ODataV2.svc/'
单元测试中的端口号在运行时发生变化。 有没有办法忽略特定属性并比较xml。
【问题讨论】: