Beispiel #1
0
        // rekursive Funktion
        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     = XmlUtility.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
                }
            }
        }
Beispiel #2
0
 private static List<xpathProp> dismantle(string xpath)
 {
     String[] xpathArray = xpath.Split('/');
     List<xpathProp> xpathDict = new List<xpathProp>();
     foreach (string s in xpathArray)
     {
         xpathProp xp = new xpathProp();
         if (s.Length > 0)
         {
             xp.nodeName = s.Substring(0, s.IndexOf('['));
             string subs = s.Substring(s.IndexOf('[') + 1, s.IndexOf(']') - s.IndexOf('[') - 1);
             xp.nodeIndex = long.Parse(subs);
         }
         else
         {
             xp.nodeName = s;
             xp.nodeIndex = 1;
         }
         xpathDict.Add(xp);
     }
     return xpathDict;
 }
Beispiel #3
0
        private static List <xpathProp> dismantle(string xpath)
        {
            String[]         xpathArray = xpath.Split('/');
            List <xpathProp> xpathDict  = new List <xpathProp>();

            foreach (string s in xpathArray)
            {
                xpathProp xp = new xpathProp();
                if (s.Length > 0)
                {
                    xp.nodeName = s.Substring(0, s.IndexOf('['));
                    string subs = s.Substring(s.IndexOf('[') + 1, s.IndexOf(']') - s.IndexOf('[') - 1);
                    xp.nodeIndex = long.Parse(subs);
                }
                else
                {
                    xp.nodeName  = s;
                    xp.nodeIndex = 1;
                }
                xpathDict.Add(xp);
            }
            return(xpathDict);
        }