Exemplo n.º 1
0
        private bool GetKeyForNode(XmlNode currentNode, string name, IXmlSetting currentSetting, out string key)
        {
            bool rc = true;

            key = "";

            try
            {
                IXmlSettingNode settingNode    = currentSetting.GetNode(name);
                List <String>   lstKeyAttrName = settingNode.identifier().Split(',').ToList <string>();
                if (lstKeyAttrName.Count > 0)
                {
                    List <string> tempKeys = new List <string>();
                    foreach (string attrNameNode in lstKeyAttrName)
                    {
                        string attrValue = currentNode.Attributes[attrNameNode].Value;
                        tempKeys.Add(attrValue);
                    }
                    key = String.Join("|", tempKeys.ToArray());
                }
            }
            catch (Exception e)
            {
                key = "";
                rc  = false;
            }
            return(rc);
        }
Exemplo n.º 2
0
        private bool GetEffectiveAttributeNames(XmlNode currentNode, string name, IXmlSetting currentSetting, out List <string> AttrNameList)
        {
            bool rc = true;

            AttrNameList = new List <string>();
            try
            {
                IXmlSettingNode settingNode          = currentSetting.GetNode(name);
                List <String>   lstEffectiveAttrName = settingNode.attributesToCompare().Split(',').ToList <string>();
                AttrNameList.AddRange(lstEffectiveAttrName);
            }
            catch (Exception e)
            {
                rc = false;
            }
            return(rc);
        }
Exemplo n.º 3
0
        private void DomToNode(IXmlSetting currentSetting, XmlNode currentNode, ref CXmlFileNodeImp parent)
        {
            bool NodeCompareFlag = false;

            try
            {
                IXmlSettingNode settingNode = currentSetting.GetNode(currentNode.Name);
                if (settingNode != null)
                {
                    NodeCompareFlag = settingNode.compare_flag;
                }
            }
            catch (Exception e)
            {
                // do nothing
            }

            if (NodeCompareFlag)
            {
                CXmlFileNodeImp neoNode = new CXmlFileNodeImp(currentNode.Name, GetXPath(currentNode));

                string key = "";
                if (GetKeyForNode(currentNode, neoNode.name, currentSetting, out key))
                {
                    neoNode.key = key;
                }
                key = neoNode.name + "|" + neoNode.key;

                if (currentNode.NodeType == XmlNodeType.Text)
                {
                    neoNode.text = currentNode.Value;
                    parent.m_childNodes.Add(neoNode.key, neoNode);
                    neoNode.m_parentNodes.Add(parent.key, parent);
                    return;
                }
                foreach (XmlAttribute xmlAttr in currentNode.Attributes)
                {
                    List <string> listOfAttrName = new List <string>();
                    GetEffectiveAttributeNames(currentNode, neoNode.name, currentSetting, out listOfAttrName);
                    if (listOfAttrName.IndexOf(xmlAttr.Name) >= 0)
                    {
                        neoNode.m_attributes.Add(xmlAttr.Name, xmlAttr.Value);
                    }
                }
                foreach (XmlNode childNode in currentNode.ChildNodes)
                {
                    DomToNode(currentSetting, childNode, ref neoNode);
                }
                if (parent.m_childNodes.ContainsKey(key))
                {
                    // dealing with duplicate key, add numeric suffix to the key
                    if (m_DuplicateKeyMemo.ContainsKey(key))
                    {
                        m_DuplicateKeyMemo[key] = m_DuplicateKeyMemo[key] + 1;
                    }
                    else
                    {
                        m_DuplicateKeyMemo.Add(key, 1);
                    }
                    key = key + "." + m_DuplicateKeyMemo[key].ToString();
                }
                parent.m_childNodes.Add(key, neoNode);
                neoNode.m_parentNodes.Add(key, parent);
            }
        }