Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Comparing XMLs

Hi,

I'm having a slight problem comparing XML's... I am using MS XML 4 to manipulate
XML data e.g.

<CAR colour="red" wheels="4">
<PASSENGER name="fred" />
<PASSENGER name="wilma" />
</CAR>

If I remove the two PASSENGER elements my resulting XML is:

<CAR colour="red" wheels="4">
</CAR>

Is there anything I do in the MS XML parser to refresh/rebuild the XML so
that it becomes:

<CAR colour="red" wheels="4" />

The problem is that I compare XML's as strings after the manipulation to
see if they are the same or not. I don't care what the difference is, I
just need to know that there is a difference.

Alternatively is there any COM components out there for comparing XML's?
I've seen something from MS but it requires the .Net framework so I wouldn't
be allowed to use it anyway.

Thanks

Alex
[999 byte] By [Alex Kennedy] at [2007-11-9 15:28:09]
# 1 Re: Comparing XMLs
I have in mind two ways to solve your problem:
- use DOM API to traverse the two parsed trees
- use a really simple XSLT stylesheet (I think that it will have around 30
lines) to do the job: one XML is the input source for the XSLT, the other
one is loaded by document() function - the name is received as a parameter.
"Alex Kennedy" <kenna2@bp.com> wrote:
>
>
>Hi,
>
>I'm having a slight problem comparing XML's... I am using MS XML 4 to manipulate
>XML data e.g.
>
><CAR colour="red" wheels="4">
> <PASSENGER name="fred" />
> <PASSENGER name="wilma" />
></CAR>
>
>If I remove the two PASSENGER elements my resulting XML is:
>
><CAR colour="red" wheels="4">
></CAR>
>
>Is there anything I do in the MS XML parser to refresh/rebuild the XML so
>that it becomes:
>
><CAR colour="red" wheels="4" />
>
>The problem is that I compare XML's as strings after the manipulation to
>see if they are the same or not. I don't care what the difference is, I
>just need to know that there is a difference.
>
>Alternatively is there any COM components out there for comparing XML's?
> I've seen something from MS but it requires the .Net framework so I wouldn't
>be allowed to use it anyway.
>
>Thanks
>
>Alex
>
>
Marian Olteanu at 2007-11-11 23:29:39 >