Solved

XmlDiff c# get node names

Posted on 2010-09-20
2
1,963 Views
Last Modified: 2012-05-10
I am using XMLDiff from microsoft to compare a series of 2 XML files. I then do a node by node copy of the result into a master document.

The trouble is that the resulting diffgram only has <node match="1"> say to show the child order from the original file but does not show the actual node names.

I have tried looking up how to do this assuming that others have wanted the same thing. Although there are many links (some even from MSDN which I have a logon for) they all point to GotDotNet.com which microsoft has closed down.

Does anyone know an easy way to get the node names out. One issue is that even if I use the original document and try to use xpath based on "match" numbers the xml declaration itself is treated as a node.As for how comments etc, are treated I am unsure at this stage.

If the GotDotNet forums are still available anywhere that may also be useful. It does seem to be poor that MSDN has links in its knowledge base to a site it has removed.
<?xml version="1.0"?>
<Response>
<RequestIdentity>123456846</RequestIdentity>
<RequestType>Heartbeat</RequestType>
<RequestSubType>All</RequestSubType>
<Response_Code>0</Response_Code>
<Response_Text>OK</Response_Text>
<ServerVersion>5.6.0.2|5.6.0.2</ServerVersion>
<Jetbet_JDate>20 Sep 2010 12:00:00a.m.</Jetbet_JDate>
<Jetbet_JTime>106783</Jetbet_JTime>
<Jetbet_Date>21 Sep 2010 5:39:43a.m.</Jetbet_Date>
<NotifyGeneration>6358</NotifyGeneration>
</Response>

results in 

 <xmldiff version="1.0" srcDocHash="10037022439851186509" options="None" fragments="no" xd="http://schemas.microsoft.com/xmltools/2002/xmldiff">
- <node match="2">
- <node match="8">
  <change match="1">106740</change> 
  </node>
- <node match="9">
  <change match="1">21/09/2010 5:39:00 a.m.</change> 
  </node>
- <node match="10">
  <change match="1">9415</change> 
  </node>
  </node>
  </xmldiff>

Open in new window

0
Comment
Question by:jetbet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 33731469
0
 

Accepted Solution

by:
jetbet earned 0 total points
ID: 33739683
I ended up writing something myself.

I have included the code below
private void GetNodePath(List<String> path, XmlNode source, XmlNode response, ref String result)
        {
            String match = XMLUtilities.GetAttributeValue(source, ".", "match");
            if (match != "")
            {
                path.Add(match);
            }
            XmlNode parent = source.ParentNode;

            if (parent == null)
            {
                try
                {
                    XmlNode temp = response;
                    for (int i = path.Count - 2; i > 0; i--)
                    {
                        temp = temp.ChildNodes[int.Parse(path[i])-1];  
                    }
                    result = temp.LocalName;
                }
                catch
                {
                    result = "";
                }
            }
            else
            {
                GetNodePath(path, parent, response, ref result);
            }
        }

Open in new window

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question