我正在尝试使用XMLUnit 2来比较xml文件。
<composite>
<data>
<subtag>
<code>1</code>
</subtag>
<subtag>
<code>2</code>
</subtag>
</data>
</composite>
第二个文件是相同的,唯一的区别是'subtag'标签切换位置。
<composite>
<data>
<subtag>
<code>2</code>
</subtag>
<subtag>
<code>1</code>
</subtag>
</data>
</composite>
到目前为止,我一直不幸找到一组适合将这两者匹配的ElementMatchers。
这个问题是否有开箱即用的解决方案?
答案 0 :(得分:1)
这与&#34; BluetoothManager btManager =(BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter btAdapter=btManager.getAdapter();
BluetoothLeScanner btScanner=btAdapter.getBluetoothLeScanner();
ScanFilter filter = new ScanFilter.Builder().setDeviceAddress("E0:E5:CF:32:95:B2").build();
List<ScanFilter> filters = new ArrayList<>();
filters.add(filter);
ScanSettings settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_BALANCED)
.setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES)
.build();
btScanner.startScan(filters,settings,leScanCallback);
private ScanCallback leScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType,result);
Log.d(ACTIVITY_TAG, String.format("message:%d %s", callbackType,result.getDevice().getAddress()));
}
}
完全相同,由嵌套ScanSettings.CALLBACK_TYPE_FIRST_MATCH|ScanSettings.CALLBACK_TYPE_MATCH_LOST
&#34;标识。例如来自XMLUnit的用户指南。一种解决方案是使用条件tr
并确保在决定采用th
时使用正确的规则 - 请参阅https://github.com/xmlunit/user-guide/wiki/SelectingNodes#conditional-elementselectors
在具体案例中,如
ElementSelector
应该这样做。这假定您的subtag
由ElementSelectors.conditionalBuilder()
.whenElementIsNamed("subtag")
.thenUse(ElementSelectors.byXPath("./code", ElementSelectors.byNameAndText))
.elseUse(ElementSelectors.byName)
.build();
子元素的嵌套文本标识。