Click here to Skip to main content
15,899,679 members

Comments by Kandiya (Top 24 by date)

Kandiya 6-Oct-15 8:30am View    
Tried as such but on doing so If there is multiple elements are missing on comparing validation error message for missing elements is shown only one after the other.
Kandiya 6-Oct-15 7:48am View    
Only the missing elements in the Input Xml are to be figured out by comparing with the Reference Xml.Value comparison of the Nodes are not required.
Kandiya 5-Oct-15 10:15am View    
Tried below code but not working .I just want the node missing on comparing. Value difference is not required.
public void CompareXmlTest1(string RefXml, string InputXml)
{

string childnodeCommon = string.Empty;
string childnode = string.Empty;

FileInfo feedList = new FileInfo(RefXml);
FileInfo feedRequest = new FileInfo(InputXml);

// Load the documents
XmlDocument feedListXmlDoc = new XmlDocument();
feedListXmlDoc.Load(RefXml);

// Load the documents
XmlDocument feedRequestXmlDoc = new XmlDocument();
feedRequestXmlDoc.Load(InputXml);

// Define a single node
XmlNode feedListNode;
XmlNode feedRequestNode;

//Get Child Node Names(New)
string feedListNodeName = string.Empty;
string feedRequestNodeName = string.Empty;
//End

// Get the root Xml element
XmlElement feedListRoot = feedListXmlDoc.DocumentElement;
XmlElement feedRequestRoot = feedRequestXmlDoc.DocumentElement;

// Get a list of feeds for the stored list and the request
XmlNodeList feedListXml = feedListRoot.SelectNodes("/Names");
XmlNodeList feedRequestXml = feedRequestRoot.SelectNodes("/Names");



if (feedListRoot.HasChildNodes && feedRequestRoot.HasChildNodes)
{


try
{
// loop through list of Ref Xml Child Nodes
for (int i = 0; i < feedListRoot.ChildNodes.Count; i++)
{
//Get Ref Xml Node
feedListNode = feedListRoot.ChildNodes.Item(i);

//Get Ref Xml Child Node Name
feedListNodeName = feedListRoot.ChildNodes.Item(i).Name.ToString();

//check Input Xml Child Nodes for any missing with the Ref Xml Child Nodes


//Get Input Xml Child Node Name
if (feedRequestRoot.ChildNodes.Item(i) != null)
{
//Get Input Xml Node
feedRequestNode = feedRequestXml.Item(i);

}
//checks to see if child node names is there or not comparing the Input Xml with Ref Xml
else
{
feedListNodeName = feedListRoot.ChildNodes.Item(i).Name.ToString();

if (string.IsNullOrEmpty(childnode) == true)
{
childnode = "Missing Child Node: " + feedListNodeName;

}
else
{
childnode += "," + feedListNodeName;

}

childnodeCommon = childnode + " for the Parent Node " + feedListRoot.Name;


}


}
}
finally
{
//Console.WriteLine("Result file has been written out at " + _resultPath);
}

}
Response.Write(childnodeCommon);
//feedListXmlDoc.Save(_resultPath);
}
Kandiya 5-Oct-15 10:13am View    
How to compare two XML files and fetch missing nodes using c#?
Tried below code but not working .
public void CompareXmlTest1(string RefXml, string InputXml)
{

string childnodeCommon = string.Empty;
string childnode = string.Empty;

FileInfo feedList = new FileInfo(RefXml);
FileInfo feedRequest = new FileInfo(InputXml);

// Load the documents
XmlDocument feedListXmlDoc = new XmlDocument();
feedListXmlDoc.Load(RefXml);

// Load the documents
XmlDocument feedRequestXmlDoc = new XmlDocument();
feedRequestXmlDoc.Load(InputXml);

// Define a single node
XmlNode feedListNode;
XmlNode feedRequestNode;

//Get Child Node Names(New)
string feedListNodeName = string.Empty;
string feedRequestNodeName = string.Empty;
//End

// Get the root Xml element
XmlElement feedListRoot = feedListXmlDoc.DocumentElement;
XmlElement feedRequestRoot = feedRequestXmlDoc.DocumentElement;

// Get a list of feeds for the stored list and the request
XmlNodeList feedListXml = feedListRoot.SelectNodes("/Names");
XmlNodeList feedRequestXml = feedRequestRoot.SelectNodes("/Names");



if (feedListRoot.HasChildNodes && feedRequestRoot.HasChildNodes)
{


try
{
// loop through list of Ref Xml Child Nodes
for (int i = 0; i < feedListRoot.ChildNodes.Count; i++)
{
//Get Ref Xml Node
feedListNode = feedListRoot.ChildNodes.Item(i);

//Get Ref Xml Child Node Name
feedListNodeName = feedListRoot.ChildNodes.Item(i).Name.ToString();

//check Input Xml Child Nodes for any missing with the Ref Xml Child Nodes


//Get Input Xml Child Node Name
if (feedRequestRoot.ChildNodes.Item(i) != null)
{
//Get Input Xml Node
feedRequestNode = feedRequestXml.Item(i);

}
//checks to see if child node names is there or not comparing the Input Xml with Ref Xml
else
{
feedListNodeName = feedListRoot.ChildNodes.Item(i).Name.ToString();

if (string.IsNullOrEmpty(childnode) == true)
{
childnode = "Missing Child Node: " + feedListNodeName;

}
else
{
childnode += "," + feedListNodeName;

}

childnodeCommon = childnode + " for the Parent Node " + feedListRoot.Name;


}


}
}
finally
{
//Console.WriteLine("Result file has been written out at " + _resultPath);
}

}
Response.Write(childnodeCommon);
//feedListXmlDoc.Save(_resultPath);
}
Kandiya 5-Oct-15 1:57am View    
I have a reference xml and an input xml.
In the input xml few child nodes are missing.
I want to fetch those missing child nodes by comparing the reference xml with the Input Xml provided.