Click here to Skip to main content
15,890,185 members
Home / Discussions / C#
   

C#

 
GeneralRe: XML file comparison output with node names Pin
Dar Brett26-Sep-18 0:44
Dar Brett26-Sep-18 0:44 
GeneralRe: XML file comparison output with node names Pin
Pete O'Hanlon25-Sep-18 8:12
mvePete O'Hanlon25-Sep-18 8:12 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan25-Sep-18 18:06
Raja Saravanan25-Sep-18 18:06 
GeneralRe: XML file comparison output with node names Pin
Pete O'Hanlon25-Sep-18 20:38
mvePete O'Hanlon25-Sep-18 20:38 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan26-Sep-18 21:02
Raja Saravanan26-Sep-18 21:02 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan2-Oct-18 20:23
Raja Saravanan2-Oct-18 20:23 
GeneralRe: XML file comparison output with node names Pin
Pete O'Hanlon2-Oct-18 20:44
mvePete O'Hanlon2-Oct-18 20:44 
GeneralRe: XML file comparison output with node names Pin
Raja Saravanan3-Oct-18 17:14
Raja Saravanan3-Oct-18 17:14 
public void ReadXmlNodes1(System.Xml.XmlNodeList nodeList, string fst)
{
string PrefixValue = string.Empty;

foreach (System.Xml.XmlNode n in nodeList)
{
{
if (LoopReturn == 1)
{
Diffnum = Positivenum - Negativenum;
if (Diffnum < 0)
{ Diffnum = 0; }
string[] fullXmlPathSplit = fullXmlPath.Split(',');
PrefixValue = string.Join(",", fullXmlPathSplit, 0, Diffnum);
iAppend = iAppend + 1;
if (Diffnum == 0)
{ Positivenum = 0; Negativenum = 0; fullXmlPath = string.Empty; iAppend = 0; }
else
{ Positivenum = Positivenum - 1; }
LoopReturn = 3; // if the loop is revising the same node tree.
}
if (fst != "First")
{
Positivenum = Positivenum + 1;
fst = "Sec";
}
if (n.ChildNodes.Count == 0)
{
if (n.InnerText != string.Empty || n.InnerText != "" || NodeTraverse != "" || NodeTraverse != string.Empty)
{
if (n.LocalName == "remove")
{
string[] tmpOuter = n.OuterXml.ToString().Split(' ');
tmpOuter = tmpOuter[1].ToString().Split('=');
string[] tmpremoveOuter = tmpOuter[1].Split('"');
if (tmpremoveOuter[1].Contains("-") || NodeTraverse != string.Empty)
{
if (tmpremoveOuter[1].Contains("-") == false)
{ NodeTraverse = NodeTraverse + "," + tmpremoveOuter[1] + " - " + n.LocalName + " = " + tmpOuter[1].ToString(); }
else
{ NodeTraverse = NodeTraverse + " - " + n.LocalName + " = " + tmpOuter[1].ToString(); }
}
else
{ NodeTraverse = NodeTraverse + "," + tmpremoveOuter[1] + " - " + n.LocalName + " = " + tmpOuter[1].ToString(); }

//Remove
if (LoopReturn == 1)
{ NodeTraverse = PrefixValue + NodeTraverse + Environment.NewLine; }
else
{ NodeTraverse = NodeTraverse + Environment.NewLine; }
File.AppendAllText(Diff_NodeNum, NodeTraverse);
NodeTraverse = "";
Positivenum = Positivenum - 1;
}
else
{
NodeTraverse = NodeTraverse + " - " + n.ParentNode.LocalName + " - " + n.InnerText;

//Final Line write
if (LoopReturn == 1)
{ NodeTraverse = PrefixValue + NodeTraverse + Environment.NewLine; }
else
{ NodeTraverse = NodeTraverse + Environment.NewLine; }
File.AppendAllText(Diff_NodeNum, NodeTraverse);
NodeTraverse = "";
Positivenum = Positivenum - 1;
}
}
else
{
string[] tmpOuter1 = n.OuterXml.ToString().Split(' ');
string[] tmpremoveOuter1 = tmpOuter1[1].Split('"');
if (tmpremoveOuter1[1] != string.Empty)
{
if (tmpremoveOuter1[1].Contains("-") || NodeTraverse != string.Empty)
{ NodeTraverse = tmpremoveOuter1[1] + " - " + n.LocalName + " - " + tmpOuter1[1].ToString(); }
else
{
if (NodeTraverse == string.Empty && PrefixValue == string.Empty && fullXmlPath == string.Empty)
{ NodeTraverse = tmpremoveOuter1[1] + " - " + n.LocalName + " - " + tmpOuter1[1].ToString(); }
else if (NodeTraverse == string.Empty && PrefixValue == string.Empty)
{ NodeTraverse = fullXmlPath + "," + tmpremoveOuter1[1] + " - " + n.LocalName + " - " + tmpOuter1[1].ToString(); }
else if (PrefixValue != string.Empty)
{ NodeTraverse = PrefixValue + "," + tmpremoveOuter1[1] + " - " + n.LocalName + " - " + tmpOuter1[1].ToString(); }
else
{ NodeTraverse = NodeTraverse + "," + tmpremoveOuter1[1] + " - " + n.LocalName + " - " + tmpOuter1[1].ToString(); }
}
}
else
{ NodeTraverse = NodeTraverse + " - " + n.LocalName + " - " + tmpOuter1[1].ToString(); }

//Write outer text
if (LoopReturn == 1)
{ NodeTraverse = PrefixValue + NodeTraverse + Environment.NewLine; }
else
{
NodeTraverse = NodeTraverse + Environment.NewLine;
}
File.AppendAllText(Diff_NodeNum, NodeTraverse);
NodeTraverse = "";
Positivenum = Positivenum - 1;
}
//LoopReturn = 3; // if the loop is revising the same node tree.
}
else
{
if (n.Attributes.Count > 0)
{
if (n.Attributes[0].Value != string.Empty || n.Attributes[0].Value != "")
{
if (string.IsNullOrEmpty(NodeTraverse) && PrefixValue == string.Empty)
{
NodeTraverse = n.Attributes[0].Value;
}
else if (PrefixValue != string.Empty)
{ NodeTraverse = PrefixValue + "," + n.Attributes[0].Value; }
else
{
NodeTraverse = NodeTraverse + "," + n.Attributes[0].Value;
}
if (LoopReturn != 3)
{ LoopReturn = 2; }
}
}
if (fullXmlPath == string.Empty)
{
if (Positivenum != 0)
if (n.Attributes.Count > 0)
{ fullXmlPath = n.Attributes[0].Value; }
else
{ fullXmlPath = fullXmlPath; }
}
else
{
if (iAppend == 0)
{
if (n.Attributes.Count > 0)
{
fullXmlPath = fullXmlPath + "," + n.Attributes[0].Value;
}
else
{ fullXmlPath = fullXmlPath; }
}
}
ReadXmlNodes1(n.ChildNodes, "Sec");
}
}
}
Negativenum = Negativenum + 1;
LoopReturn = 1;
}

Here is a piece of code from which I am trying to get the node names with numbers. The numbers are generated from diffgram given by microsoft.
The output I am trying to get is the node name and numbers for the changes only in separate file.

XML Output
<xd:xmldiff version="1.0" srcdochash="4699671197287989432" options="IgnoreChildOrder IgnoreComments IgnoreNamespaces IgnorePrefixes IgnoreWhitespace " fragments="yes" xmlns:xd="http://schemas.microsoft.com/xmltools/2002/xmldiff"><xd:node match="3"><xd:node match="4"><xd:node match="2"><xd:remove match="10" subtree="no"><xd:remove match="1" subtree="no"><xd:remove match="1"><xd:remove match="2-8" opid="1"><xd:remove match="2"><xd:node match="12"><xd:node match="1"><xd:node match="1"><xd:change match="1">192.168.2.200<xd:add match="/3/4/2/10/1/2-8" opid="1"><xd:remove match="2-8"><xd:node match="2"><xd:change match="@revision">9<xd:node match="2"><xd:add><hitem revision="9" version="2003" what="SCD Export" when="2018-09-19T06:38:25Z" xmlns="http://www.iec.ch/61850/2003/SCL"><xd:node match="8"><xd:node match="7"><xd:node match="1"><xd:node match="2"><xd:node match="1"><xd:node match="6"><xd:add><fcda doname="TotPF" fc="MX" ldinst="LD0" lnclass="MMXU" lninst="1" prefix="PEAV" xmlns="http://www.iec.ch/61850/2003/SCL"><xd:add><fcda doname="TotVA" fc="MX" ldinst="LD0" lnclass="MMXU" lninst="1" prefix="PEMI" xmlns="http://www.iec.ch/61850/2003/SCL"><xd:node match="4"><xd:remove match="22"><xd:node match="11"><xd:change match="@confRev">200<xd:node match="12"><xd:change match="@confRev">200<xd:remove match="6" subtree="no"><xd:remove match="7" subtree="no"><xd:remove match="1" subtree="no"><xd:remove match="1|4"><xd:remove match="2" subtree="no"><xd:remove match="16"><xd:remove match="3" subtree="no"><xd:remove match="3-4"><xd:remove match="1" opid="2"><xd:remove match="2"><xd:remove match="2|4-15|17-103"><xd:remove match="1" subtree="no"><xd:remove match="11|13|18-25|27-28" opid="3"><xd:remove match="3|5-6|10|12|14-17|26|29"><xd:remove match="4" subtree="no"><xd:remove match="18"><xd:remove match="1-17" opid="4"><xd:remove match="1-2|30"><xd:remove match="9" subtree="no"><xd:remove match="1-3" opid="5"><xd:remove match="7-8|31"><xd:remove match="3"><xd:remove match="4-5" opid="6"><xd:remove match="1-3|6"><xd:node match="20"><xd:node match="7"><xd:node match="1"><xd:node match="2"><xd:node match="1"><xd:add match="/3/6/7/1/2/1/11|13|18-25|27-28" opid="3"><xd:add match="/3/20/7/1/2/1/3|5-6|11|13|15-18|27|30" opid="7"><xd:add type="1" name="DataSet" ns="http://www.iec.ch/61850/2003/SCL"><xd:add type="2" name="name">StatUrgA<xd:add match="/3/20/7/1/2/1/4/19-20" opid="8"><xd:add><fcda doname="Op" fc="ST" ldinst="LD0" lnclass="PFRC" lninst="5" prefix="FR" xmlns="http://www.iec.ch/61850/2003/SCL"><xd:add match="/3/20/7/1/2/1/4/17-18" opid="9"><xd:add match="/3/6/7/1/2/1/4/1-17" opid="4"><xd:add match="/3/6/7/1/2/3/1" opid="2"><xd:add match="/3/20/7/1/2/1/2|7|10" opid="10"><xd:add type="1" name="ReportControl" ns="http://www.iec.ch/61850/2003/SCL"><xd:add type="2" name="bufTime">100<xd:add type="2" name="buffered">true<xd:add type="2" name="confRev">200<xd:add type="2" name="datSet">StatUrgA<xd:add type="2" name="intgPd">3000<xd:add type="2" name="name">rcbStatUrgA<xd:add type="2" name="rptID">AA1H213DR1LD0/LLN0.rcbStatUrgA<xd:add match="/3/6/7/1/2/1/9/1-3" opid="5"><xd:add match="/3/20/7/1/2/1/9|31" opid="11"><xd:remove match="12|14|19-26|28-29"><xd:remove match="3|5-6|11|13|15-18|27|30" opid="7"><xd:remove match="4" subtree="no"><xd:remove match="19-20" opid="8"><xd:remove match="17-18" opid="9"><xd:remove match="1-16|21-22"><xd:remove match="1"><xd:remove match="2|7|10" opid="10"><xd:remove match="8"><xd:remove match="9|31" opid="11"><xd:node match="16"><xd:node match="6"><xd:node match="1"><xd:node match="2"><xd:node match="1"><xd:remove match="4"><xd:add match="/3/20/4-5" opid="12"><xd:remove match="3-4"><xd:descriptor opid="1" type="move"><xd:descriptor opid="2" type="move"><xd:descriptor opid="3" type="move"><xd:descriptor opid="4" type="move"><xd:descriptor opid="5" type="move"><xd:descriptor opid="6" type="move"><xd:descriptor opid="7" type="move"><xd:descriptor opid="8" type="move"><xd:descriptor opid="9" type="move"><xd:descriptor opid="10" type="move"><xd:descriptor opid="11" type="move"><xd:descriptor opid="12" type="move">

Expected Output
22. IED Attribute: AA1L3114AR1 || 5. AccessPoint Attribute: LD0 || 0. Server || 1. LDevice Attribute: Protection || 0. LN0 Attribute: Protection LLN0 ||

I get it for some files but it crashes for others as it does not have attributes some times but has child with same name with out attribute but has the description different. Cases keep changing all time.Confused | :confused:
Or if any other ways to find difference between 2 xml file.
QuestionIssue with Land Registry Service reference.cs Pin
Member 1387432624-Sep-18 3:57
Member 1387432624-Sep-18 3:57 
AnswerRe: Issue with Land Registry Service reference.cs Pin
OriginalGriff24-Sep-18 4:08
mveOriginalGriff24-Sep-18 4:08 
AnswerRe: Issue with Land Registry Service reference.cs Pin
Richard Deeming24-Sep-18 7:56
mveRichard Deeming24-Sep-18 7:56 
GeneralRe: Issue with Land Registry Service reference.cs Pin
glennPattonWork325-Sep-18 0:52
professionalglennPattonWork325-Sep-18 0:52 
QuestionHow to get last day of specific date Pin
thepast23-Sep-18 18:11
thepast23-Sep-18 18:11 
AnswerRe: How to get last day of specific date Pin
Mycroft Holmes23-Sep-18 20:32
professionalMycroft Holmes23-Sep-18 20:32 
AnswerRe: How to get last day of specific date Pin
Maciej Los23-Sep-18 21:17
mveMaciej Los23-Sep-18 21:17 
GeneralRe: How to get last day of specific date Pin
OriginalGriff23-Sep-18 21:38
mveOriginalGriff23-Sep-18 21:38 
GeneralRe: How to get last day of specific date Pin
Maciej Los23-Sep-18 22:02
mveMaciej Los23-Sep-18 22:02 
GeneralRe: How to get last day of specific date Pin
OriginalGriff23-Sep-18 22:26
mveOriginalGriff23-Sep-18 22:26 
AnswerRe: How to get last day of specific date Pin
OriginalGriff23-Sep-18 21:38
mveOriginalGriff23-Sep-18 21:38 
AnswerRe: How to get last day of specific date Pin
Richard MacCutchan23-Sep-18 21:54
mveRichard MacCutchan23-Sep-18 21:54 
QuestionStackoverflow Pin
Thomas Kiær23-Sep-18 0:28
Thomas Kiær23-Sep-18 0:28 
AnswerRe: Stackoverflow Pin
OriginalGriff23-Sep-18 1:13
mveOriginalGriff23-Sep-18 1:13 
GeneralRe: Stackoverflow Pin
Thomas Kiær23-Sep-18 5:45
Thomas Kiær23-Sep-18 5:45 
GeneralRe: Stackoverflow Pin
OriginalGriff23-Sep-18 6:04
mveOriginalGriff23-Sep-18 6:04 
GeneralRe: Stackoverflow Pin
Thomas Kiær23-Sep-18 6:14
Thomas Kiær23-Sep-18 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.