Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

XML - compare

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ve - 19 Jan 2008 13:51 GMT
Hi,
I have two XmlDocument object. In fact this is one xml, but one is from
internet, other from data base.

I would like to compare this xml’s. I would like to check if this two
xml’s in fact is the same.

But this xml’s hava some differences like:
-empty tags can be written in two forms <tag></tag> or  <tag />,
-xml’s could be created on two different strings, where ends of the line
could be written like: „\n” or „\r\n”,
-in tags can be html,  characters like '<' and '>' can be like written
like '&lt;' and '&gt',
or characters '<' and '>' can be inside the block of <![CDATA[ something
]]>

But I know, that in fact this is the same xml, with the same content.
I have this problem for a long time and I’m not able to resolve it.
Thanks for help
Martin Honnen - 19 Jan 2008 14:31 GMT
> I have two XmlDocument object. In fact this is one xml, but one is from
> internet, other from data base.
>
> I would like to compare this xml’s. I would like to check if this two
> xml’s in fact is the same.

Check out the XML diff and patch tool:
<URL:http://msdn2.microsoft.com/en-us/xml/bb190622.aspx>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Ve - 19 Jan 2008 21:00 GMT
Martin Honnen pisze:
>> I have two XmlDocument object. In fact this is one xml, but one is
>> from internet, other from data base.
[quoted text clipped - 3 lines]
> Check out the XML diff and patch tool:
> <URL:http://msdn2.microsoft.com/en-us/xml/bb190622.aspx>

But I have forgotten to say that I would like to do it in C# code.

Thanks for help
Sergiu DUDNIC - 20 Jan 2008 09:03 GMT
Hello,

In your case, because you must compare the same things, I see 2 ways:
1) Bring both documents to the same format, after that compare it (in
particular case, you can
   a) remove all the "redundant formatting"(like \n, &lt, "-' ) from both
documents, and compare contents only or
   b) bring both "redundant formatting" to a same "standard"
   c) bring one of documents to the format of other and compare them

You can use also try to use the XML Diff & Patch GUI Tool

/serhio

> Hi,
> I have two XmlDocument object. In fact this is one xml, but one is from
[quoted text clipped - 15 lines]
> I have this problem for a long time and I’m not able to resolve it.
> Thanks for help
Ve - 20 Jan 2008 10:38 GMT
Sergiu DUDNIC pisze:
> Hello,
>
[quoted text clipped - 7 lines]
>
> You can use also try to use the XML Diff & Patch GUI Tool
[...]

But, how to make XmlDocument to return the same standard in case
<tag></tag> and </tag> ?

I can remove all "&lt" etc, but what should I do in case <![CDATA[
something ]]> ?
Martin Honnen - 20 Jan 2008 14:39 GMT
> But, how to make XmlDocument to return the same standard in case
> <tag></tag> and </tag> ?

I don't see the problem, whether the markup in the XML document is
<foo></foo> or <foo/> or <foo />, in the DOM object model or in the
XPath data model you will have an element node with name foo and no
child elements so you can simply compare on the node type, on the node
name and if needed on the child nodes.

> I can remove all "&lt" etc, but what should I do in case <![CDATA[
> something ]]> ?

Well you could use the XPath data model which only knows text nodes and
does not distinguish between text nodes and CDATA section nodes. Or your
comparison code would need to ensure that text nodes and cdata section
nodes are compared based on the node value, that will be the same then
whether you have e.g.
  <foo>a &amp; b</foo>
or
  <foo><![CDATA[a & b]]></foo>
does not matter, you will still have the same node value.

As for line endings, with .NET 2.0 and later, if you use
XmlReader.Create to parse your XML, then line endings are normalized
anyway as the XML specification requires. Thus if you work with
System.Xml.XmlDocument then use e.g.
  XmlDocument doc1 = new XmlDocument();
  doc1.Load(XmlReader.Create("file1.xml"));
instead of
  XmlDocument doc1 = new XmlDocument();
  doc1.Load("file1.xml");
then line endings are normalized and your comparison code does not have
to worry about that.
Signature


    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.