コード例 #1
0
        private SemDomQuestion GetQuestion(XmlReader reader, out string ws)
        {
            ws = string.Empty;
            SemDomQuestion result = new SemDomQuestion();

            if (reader.LocalName != "CmDomainQ")
            {
                return(result);                 // If we weren't on the right kind of node, return empty SemDomQuestion
            }
            string name = reader.LocalName;

            while (reader.Read())
            {
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        switch (reader.LocalName)
                        {
                        case "Question":
                            result.Question = GetStr(reader, out ws);
                            break;

                        case "ExampleWords":
                            result.ExampleWords = GetStr(reader, out ws);
                            break;

                        case "ExampleSentences":
                            result.ExampleSentences = GetStr(reader, out ws);
                            break;
                        }
                    }
                    break;

                    case XmlNodeType.EndElement:
                        if (reader.LocalName == "CmDomainQ")
                        {
                            // Advance past closing element before returning
                            reader.Read();
                            return(result);
                        }
                        break;
                    }
                }
            }
            return(result);
        }
コード例 #2
0
        public override void PopulateFromXml(XmlReader reader)
        {
            if (reader.LocalName != "CmSemanticDomain")
            {
                return;                  // If we weren't on the right kind of node, do nothing
            }
            GuidStr = reader.GetAttribute("guid");
            string ws = string.Empty;             // Used as the out param in GetStr()

            // Note that if the writing systems in the SemDom.xml file are inconsistent, then
            // using a single out parameter everywhere may create inconsistent results. If we
            // ever need to parse a SemDom.xml with multiple writing systems in it, we might
            // have to change how we handle the "out ws" parameters in this function.
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                {
                    switch (reader.LocalName)
                    {
                    case "CmSemanticDomain":
                        var child = new CanonicalSemanticDomainItem();
                        child.PopulateFromXml(reader);
                        AppendChild(child);
                        break;

                    case "Abbreviation":
                        string abbrev = GetStr(reader, out ws);
                        AddAbbrev(ws, abbrev);
                        break;

                    case "Name":
                        string name = GetStr(reader, out ws);
                        AddName(ws, name);
                        break;

                    case "Description":
                        string desc = GetStr(reader, out ws);
                        AddDescription(ws, desc);
                        break;

                    case "OcmCodes":
                        List <string> ocmCodes     = GetExtraDataList <string>("OcmCodes");
                        string        ocmCodesText = GetStr(reader, out ws);
                        ocmCodes.AddRange(ocmCodesText.Split(new string[] { ";  " }, StringSplitOptions.None));
                        break;

                    case "LouwNidaCodes":
                        List <string> louwNidaCodes     = GetExtraDataList <string>("OcmCodes");
                        string        louwNidaCodesText = GetStr(reader, out ws);
                        louwNidaCodes.AddRange(louwNidaCodesText.Split(new string[] { ";  " }, StringSplitOptions.None));
                        break;

                    case "CmDomainQ":
                        Dictionary <string, List <SemDomQuestion> > questionsDict = GetExtraDataWsDict <SemDomQuestion>("Questions");
                        SemDomQuestion        question  = GetQuestion(reader, out ws);
                        List <SemDomQuestion> questions = GetListFromDict <SemDomQuestion>(questionsDict, ws);
                        questions.Add(question);
                        break;
                    }
                    break;
                }

                case XmlNodeType.EndElement:
                {
                    if (reader.LocalName == "CmSemanticDomain")
                    {
                        Key = AbbrevByWs(KeyWs);
                        reader.Read();                                         // Skip past the closing element before returning
                        return;
                    }
                    break;
                }
                }
            }
        }