示例#1
0
        /// <summary>
        /// Parses a &lt;parameters&gt; or &lt;set&gt; element in an XML parameter document          
        /// </summary>
        /// <param name="Parser"></param>
        /// <param name="aNode"></param>
        /// <param name="Params"></param>
        /// <param name="bModify"></param>
        private void readParamNode(TXMLParser Parser, XmlNode aNode, ref TParameterSet Params, bool bModify)
        {
            XmlNode childNode;
            TParameterSet newParams;
            string sTag,
            sValues,
            sChildName,
            sLang,
            sDummy;

            try
            {
                Params.sName = Parser.getAttrValue(aNode, "name");                        // Name and version information. The
                Params.sEnglishName = Params.sName;
                if (Params.bRootNode())                                                     //   version is passed to child sets
                    Params.sVersion = Parser.getAttrValue(aNode, "version");               //   during creation

                childNode = Parser.firstElementChild(aNode, "translate");                 // See if tbere's a translation of the name matching our current language setting
                while (childNode != null)
                {
                    sLang = Parser.getAttrValue(childNode, "lang");
                    sDummy = Parser.getText(childNode);
                    Params.addTranslation(sLang, sDummy);
                    childNode = Parser.nextElementSibling(childNode, "translate");
                }

                if (!bModify)                                                           // If we are not modifying an existing
                    while (Params.iChildCount() > 0)                                           //   parameter set, then clear any old
                        Params.deleteChild(Params.iChildCount() - 1);                              //   child parameter sets

                sValues = Parser.getAttrValue(aNode, "locales").Trim();                     // Populate the locale list
                Params.setLocaleText(sValues);

                childNode = Parser.firstElementChild(aNode, "par");                       // Parse the <par> elements
                while (childNode != null)
                {
                    sTag = Parser.getAttrValue(childNode, "name");
                    sValues = Parser.getText(childNode);
                    readParamValues(ref Params, sTag, sValues, bModify);
                    childNode = Parser.nextElementSibling(childNode, "par");
                }
                Params.deriveParams();

                childNode = Parser.firstElementChild(aNode, "set");                       // Create child parameter sets from the
                while (childNode != null)                                                   //   <set> elements
                {
                    if (!bModify)
                        newParams = Params.addChild();
                    else
                    {                                                                      // If we are modifying an existing
                        sChildName = Parser.getAttrValue(childNode, "name");                  //  parameter set, then locate the child
                        newParams = Params.getChild(sChildName);                              //   set that we are about to parse
                        if (newParams == null)
                            newParams = Params.addChild();
                    }
                    readParamNode(Parser, childNode, ref newParams, bModify);
                    childNode = Parser.nextElementSibling(childNode, "set");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }