1

I want to compare two XML files. I am using XMLUnit to compare. I am having some problem while comparing like the following xml snippets.

Expected:

<Detail>
    <Participant>
        <PersonalInfo>
        <SSN>405018111</SSN>
        <!--<Title>MR</Title>-->
    </PersonalInfo>
    <!--<PersonalDemo>
        <Email>someemail@email.com</Email>
        <EDeliveryFlag>true</EDeliveryFlag>
    </PersonalDemo>-->
</Detail>

ACTUAL:

<Detail>
    <Participant>
        <PersonalInfo>
        <SSN>405018111</SSN>
        <Title>MR</Title>
    </PersonalInfo>
    <PersonalDemo>
        <Email>someemail@email.com</Email>
        <EDeliveryFlag>false</EDeliveryFlag>
    </PersonalDemo>
</Detail>
  1. It will fail, because "Title" tag is missing (because it is commented out) in EXPECTED while it is present in ACTUAL
  2. It will fail, because "PersonalDemo" tag is missing (because it is commented out) in EXPECTED while it is present in ACTUAL
  3. It will fail, because, "PPSDetails" has different number of child nodes (because commented out nodes are not considered) in EXPECTED and in ACTUAL

What I actually need is that I want to ignore those Elements in ACTUAL that are commented out in EXPECTED

any help please

Muhammad Ijaz
  • 181
  • 1
  • 4
  • 15
  • What's enforcing the requirement for those elements? If it's a DTD or Schema, you can parse without validation. If it's your application, you'll have to negotiate this with the application, and/or fill in dummy values. – keshlam Mar 24 '14 at 14:13
  • Actually the ACTUAL is generated out by our application. The commented out part in EXPECTED is different every time in the ACTUAL when it is generated. That is why I don't want to compare the commented out part – Muhammad Ijaz Mar 24 '14 at 14:17

1 Answers1

0

I suggest you have to write your own XML parser so that it can see get the tags which you want to ignore. In this task you simply remove the ignored tags from expected and actual XML and match others tags for validation or comparison.

I think you have two options here either use one of them between two parsers:

DOM parser
SAX PArser

I know it's not best solution, so other thoughts are also welcome...

EDIT

I believe you need to write the wrapper on XMLUint. Which will take XML input after removing of ignored tags(Wrapper Task) and rest of functionality is same.

Imran
  • 5,376
  • 2
  • 26
  • 45
  • I cannot remove the tags from the ACTUAL, because it is system generated – Muhammad Ijaz Mar 24 '14 at 14:51
  • I believe you need to write the wrapper on XMLUint. Which will take XML input after removing of ignored tags(Wrapper Task) and rest of functionality is same. – Imran Mar 24 '14 at 15:02