AppendAttribute() public static method

Append an attribute with the specified name and value to parent.
public static AppendAttribute ( XmlNode parent, string attrName, string attrVal ) : void
parent System.Xml.XmlNode
attrName string
attrVal string
return void
Ejemplo n.º 1
0
        private void MergeCustomGroups(XmlNode parentNode, XmlNodeList customGroupNodeList)
        {
            if (customGroupNodeList == null || customGroupNodeList.Count == 0)
            {
                return;                 // Stop recursing in this method.
            }
            foreach (XmlNode customGroupNode in customGroupNodeList)
            {
                string  customGroupId        = XmlUtils.GetManditoryAttributeValue(customGroupNode, "id");
                XmlNode srcMatchingGroupNode = parentNode.SelectSingleNode("group[@id='" + customGroupId + "']");
                if (srcMatchingGroupNode == null)
                {
                    // Import the entire custom node.
                    m_document.DocumentElement.AppendChild(m_document.ImportNode(customGroupNode, true));
                }
                else
                {
                    // 1. Import new strings, or override extant strings with custom strings.
                    foreach (XmlNode customStringNode in customGroupNode.SelectNodes("string"))
                    {
                        string  customId              = XmlUtils.GetManditoryAttributeValue(customStringNode, "id");
                        string  customTxt             = GetTxtAtributeValue(customStringNode);
                        XmlNode srcMatchingStringNode = srcMatchingGroupNode.SelectSingleNode("string[@id='" + customId + "']");
                        if (srcMatchingStringNode == null)
                        {
                            // Import the new string into the extant group.
                            srcMatchingGroupNode.AppendChild(m_document.ImportNode(customStringNode, true));
                        }
                        else
                        {
                            // Replace the original value with the new value.
                            // The 'txt' attribute is optional, but it will be added as a cpoy of the 'id' here, if needed.
                            string srcTxt = XmlUtils.GetOptionalAttributeValue(srcMatchingStringNode, "txt");
                            if (srcTxt == null)
                            {
                                XmlUtils.AppendAttribute(srcMatchingStringNode, "txt", customTxt);
                            }
                            else
                            {
                                srcMatchingStringNode.Attributes["txt"].Value = customTxt;
                            }
                        }
                    }

                    // 2. Group elements can be nested, so merge them, too.
                    MergeCustomGroups(srcMatchingGroupNode, customGroupNode.SelectNodes("group"));
                }
            }
        }