private static void handle(XmlNode root, XmlDocument doc, XmlDocument temp)
{
foreach (XmlNode node in root.ChildNodes)
{
Debug.WriteLine(node.Name);///////////////////////////////////////////////////////////////////////////
if (node.HasChildNodes)
{
string xpath = FindXPath(node); // xpath in doc
long number = 1;
List<xpathProp> xpathDict = dismantle(xpath); // divide xpath
string xpathTemp = "";
for (int i = 1; i < xpathDict.Count; i++)
xpathTemp += "/" + xpathDict[i].nodeName + "[1]"; // atapt xpath to template
for (int j = xpathDict.Count - 1; j >= 0; j--)
{
xpathProp xp = xpathDict[j];
if (xp.nodeIndex > number)
number = xp.nodeIndex; // get node index "number"
}
XmlNode tempNode = temp.SelectSingleNode(xpathTemp); // get node from template
if (tempNode != null && tempNode.Attributes.Count > 0)
{
foreach (XmlAttribute a in tempNode.Attributes)
{
try // transfer all attributes from tamplate node to doc node
{
XmlAttribute b = doc.CreateAttribute(a.Name);
if (a.Name == "number") // handle node index "number"
b.Value = number.ToString();
else
b.Value = a.Value;
node.Attributes.Append(b);
}
catch
{
}
}
}
handle(node, doc, temp); // next level recursively
}
}
}