0

I am developing application in which I have to compare 2 xml based on the IPADDRESS tag which is unique. Ex: input1.xml

          <DeviceList>
                <Device>
                  <IPAddress>20.20.1.20</IPAddress>
                  <HostName>Device1</HostName>
                </Device>
                <Device>
                  <IPAddress>20.20.1.21</IPAddress>
                  <HostName>Device2</HostName>
                </Device>
                <Device>
                  <IPAddress>20.20.1.22</IPAddress>
                  <HostName>Device3</HostName>
                </Device>
           </DeviceList>

            inpu2.xml
          <DeviceList>
                <Device>
                  <IPAddress>20.20.1.23</IPAddress>
                  <HostName>Device1</HostName>
                </Device>
                <Device>
                  <IPAddress>20.20.1.21</IPAddress>
                  <HostName>Device3</HostName>
                </Device>
                <Device>
                  <IPAddress>20.20.1.22</IPAddress>
                  <HostName>Device3</HostName>
                </Device>
         </DeviceList>

Result should be two xmls 
output1 : ipadrees are present in input2.xml and not present in input.xml1


  <DeviceList>
      <Device>
          <IPAddress>10.20.1.23</IPAddress>
          <HostName>Device1</HostName>
      </Device>
  </DeviceList>

output2 : Remaining device list in input1.xml

 <DeviceList>
          <Device>
      <IPAddress>10.20.1.20</IPAddress>
      <HostName>Device1</HostName>
    </Device>
    <Device>
      <IPAddress>10.20.1.21</IPAddress>
      <HostName>Device2</HostName>
    </Device>
    <Device>
      <IPAddress>10.20.1.22</IPAddress>
      <HostName>Device3</HostName>
    </Device>
  </DeviceList>

I tried using XMLUNIT java api but not able to do as we should filter only based on IPAddress tag.Please help and thanks in advance.

Akshobhya
  • 169
  • 2
  • 16

1 Answers1

0

I assume you are collecting the differences between the two documents and want to emit the ones where the difference is CHILD_LOOKUP and only use those where the side representing input1 is null.

What you need here is the exact same as the HTML Table example from https://github.com/xmlunit/user-guide/wiki/SelectingNodes - you want an ElementQualifier that usually matches XML elements by name but in the special case of the Device element you want to match those elements that have the same text content inside of their IPAddress child element.

This would be something like

ElementSelectors.conditionalBuilder()
    .whenElementIsNamed("Device")
        .thenUse(ElementSelectors.byXPath("./IPAddress", ElementSelectors.byNameAndText))
    .elseUse(ElementSelectors.byName)
    .build();
Stefan Bodewig
  • 3,260
  • 15
  • 22