Пример #1
0
        public bool ReadXmlNode(System.Xml.XmlNode node, Hashtable languages)
        {
            bool Success = true;

            m_fEndWithField = false;
            m_fEndWithWord  = false;
            foreach (System.Xml.XmlAttribute Attribute in node.Attributes)
            {
                // Create new attribute details, which may be altered later on:
                string newValue = Attribute.Value;
                switch (Attribute.Name)
                {
                case "element":
                    m_XmlElementName = Attribute.Value;
                    break;

                case "begin":
                    m_Begin = Attribute.Value;
                    break;

                case "end":
                case "endList":
                    STATICS.SplitString(newValue, delim, ref m_EndList);
                    break;

                case "endWithField":
                    m_fEndWithField = IsTrue(Attribute.Value);
                    break;

                case "endWithWord":
                    m_fEndWithWord = IsTrue(Attribute.Value);
                    break;

                /*
                 * case "lang":
                 * // Look up replacement language name:
                 * ClsLanguage language = languages[Attribute.Value] as ClsLanguage;
                 * if (language == null)
                 * {
                 *      Converter.Log.AddError("Error in Mapping File: Unknown 'lang' value '" + Attribute.Value + "' in the 'fieldDescriptions' section.");
                 *      m_xmlLanguage = newValue;
                 * }
                 * else
                 *      m_xmlLanguage = language.XmlLang;
                 *
                 * m_Language = newValue;
                 * break;
                 * */
                case "lang":
                    newValue = null;
                    // Look up replacement language name:
                    ClsLanguage language = languages[Attribute.Value] as ClsLanguage;
                    if (language != null)
                    {
                        newValue   = language.XmlLang;
                        m_Language = language.KEY;
                        m_xmlLang  = language.XmlLang;
                    }
                    else
                    {
                        Converter.Log.AddError(String.Format(Sfm2XmlStrings.UnknownLangValue0InTheInFieldMarkers, Attribute.Value));
                        newValue = Attribute.Value;
                    }
                    break;

                case "style":
                    m_style = Attribute.Value;
                    break;

                case "ignore":
                    m_ignore = STATICS.IsBoolString(Attribute.Value, false);
                    break;

                default:
                    Converter.Log.AddWarning(String.Format(Sfm2XmlStrings.UnknownAttribute0InTheInFieldMarkers, Attribute.Name));
                    Success = false;
                    break;
                }
            }

            if (m_Begin == null)
            {
                Converter.Log.AddError(Sfm2XmlStrings.BeginNotDefinedInAnInFieldMarker);
                Success = false;
            }
            if (m_EndList.Count == 0 && !m_fEndWithWord && !m_fEndWithField)
            {
                Converter.Log.AddError(String.Format(Sfm2XmlStrings.InFieldMarker0HasNoEndAttribute, m_Begin));
                Success = false;
            }
            if (m_XmlElementName == null)
            {
                Converter.Log.AddError(String.Format(Sfm2XmlStrings.InFieldMarker0HasNoElementNameAttribute, m_Begin));
                Success = false;
            }

            return(Success);
        }
        public bool ReadXmlNode(System.Xml.XmlNode fieldNode, Hashtable languages, string topAnalysisWS)
        {
            m_OtherAttributes = "";
////			string allAttributes = "<field ";

            foreach (System.Xml.XmlAttribute Attribute in fieldNode.Attributes)
            {
                // Create new attribute details, which may be altered later on:
                string NewName  = Attribute.Name;
                string NewValue = Attribute.Value;
                switch (Attribute.Name)
                {
                case "sfm":
                    m_Sfm = Attribute.Value;
                    break;

                case "name":
                    m_Name = Attribute.Value;
                    break;

                case "type":
                    m_Type = Attribute.Value;
                    break;

                case "lang":
////						NewName = "xml:lang";
////						NewValue = Attribute.Value;
                    // Look up replacement language name:
                    ClsLanguage language = languages[Attribute.Value] as ClsLanguage;
                    if (language == null)
                    {
                        Converter.Log.AddError(String.Format(Sfm2XmlStrings.UnknownLangValue0InFieldDescs, Attribute.Value));
                        m_xmlLanguage = NewValue;
                    }
                    else
                    {
                        m_xmlLanguage = language.XmlLang;
                    }

                    m_Language = NewValue;
                    break;

                case "abbr":
                    IsAbbr = STATICS.IsBoolString(Attribute.Value, true);
                    break;

                case "exclude":
                    IsExcluded = STATICS.IsBoolString(Attribute.Value, false);
                    break;

                case "autoImport":
                    IsAutoImportField = STATICS.IsBoolString(Attribute.Value, false);
                    break;

                case "autoSfm":                         // just ignore for now and re-assign
                    break;

                default:
                    m_OtherAttributes += " " + NewName + "=\"" + NewValue + "\"";
                    break;
                }
////				allAttributes += " " + NewName + "=\"" + NewValue + "\"";
            }

////			allAttributes += ">";

            // Iterate through all the attributes of the "meaning" sub-element of this field:
            System.Xml.XmlNode Meaning = fieldNode.SelectSingleNode("meaning");
            if (Meaning == null)
            {
                Converter.Log.AddError(String.Format(Sfm2XmlStrings.MissingMeaningElementInField0InFieldDescs, m_Sfm));
            }
            else
            {
                m_Meaning = "<meaning ";

                foreach (System.Xml.XmlAttribute Attribute in Meaning.Attributes)
                {
                    m_Meaning += Attribute.Name + "=\"" + Attribute.Value + "\" ";
                    if (Attribute.Name == "app")
                    {
                        m_meaningApp = Attribute.Value;
                    }
                    else if (Attribute.Name == "id")
                    {
                        m_meaningId = MakeValidFwId(Attribute.Value);
                    }
                    else if (Attribute.Name == "func")
                    {
                        m_RefFunc = Attribute.Value;
                    }
                    else if (Attribute.Name == "funcWS")
                    {
                        m_RefFuncWS = Attribute.Value;
                    }
                }
                m_Meaning += " />";

                RebuildMeaningEntry(null, topAnalysisWS);
            }

//			xmlOutput.WriteRaw(System.Environment.NewLine + "</field>" + System.Environment.NewLine);

            SetAutoSfm();
            if (m_Sfm == null)
            {
                Converter.Log.AddError(Sfm2XmlStrings.FieldDefinedWithNoSfmAttributeInTheFieldDescs);
            }
            else if (m_Language == null)
            {
                Converter.Log.AddError(String.Format(Sfm2XmlStrings.FieldDescWithSFMOf0HasNoLangAttribute, m_Sfm));
            }
            if (m_Type == null)
            {
                Converter.Log.AddWarning(String.Format(Sfm2XmlStrings.FieldDescWithSFMOf0HasNoTypeAttribute, m_Sfm));
            }
            else
            {
                return(true);
            }

            return(false);
        }