Exemple #1
0
        protected virtual void OnReadMetadata(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                return;
            }

            string startName = reader.Name;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "keyword":
                        KeywordItem keyItem = new KeywordItem();
                        keyItem.ReadXml(reader);
                        if (!keyItem.IsEmpty)
                        {
                            _keywords.Add(keyItem);
                        }
                        break;

                    case "attribute":
                        AttributeItem attrItem = new AttributeItem();
                        attrItem.ReadXml(reader);
                        if (!attrItem.IsEmpty)
                        {
                            _attributes.Add(attrItem);
                        }
                        break;

                    case "authoring":
                        break;
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, startName,
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
Exemple #2
0
        protected virtual bool OnLoadTopicMetadata()
        {
            if (_filePath == null || !_filePath.Exists)
            {
                return(false);
            }

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments               = true;
            settings.IgnoreWhitespace             = true;
            settings.IgnoreProcessingInstructions = true;

            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(_filePath, settings);

                XmlNodeType nodeType = reader.MoveToContent();
                Debug.Assert(nodeType == XmlNodeType.Element);
                if (nodeType != XmlNodeType.Element)
                {
                    return(false);
                }

                if (String.Equals(reader.Name, "topic",
                                  StringComparison.OrdinalIgnoreCase))
                {
                    _includesTopicId = true;

                    _topicId = reader.GetAttribute("id");
                    string strTemp = reader.GetAttribute("revisionNumber");
                    if (!String.IsNullOrEmpty(strTemp))
                    {
                        _revNumber = Convert.ToInt32(strTemp);
                    }

                    string nodeName = null;
                    while (reader.Read())
                    {
                        nodeType = reader.NodeType;
                        nodeName = reader.Name;
                        if (nodeType == XmlNodeType.Element)
                        {
                            if (ConceptualUtils.IsValidDocumentTag(nodeName))
                            {
                                this.OnDocumentType(nodeName);

                                break;
                            }
                        }
                        else if (nodeType == XmlNodeType.EndElement)
                        {
                            if (String.Equals(nodeName, "topic") ||
                                ConceptualUtils.IsValidDocumentTag(nodeName))
                            {
                                this.OnDocumentType(nodeName);

                                break;
                            }
                        }
                    }
                }
                else if (ConceptualUtils.IsValidDocumentTag(reader.Name))
                {
                    _includesTopicId = false;

                    this.OnDocumentType(reader.Name);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            // If the companion file is available, load it...
            string companionFile = Path.ChangeExtension(_filePath, ".cmp");

            if (!File.Exists(companionFile))
            {
                return(true);
            }

            try
            {
                reader = XmlReader.Create(companionFile, settings);

                XmlNodeType nodeType = XmlNodeType.None;
                string      nodeName = null;
                string      nodeText = null;
                while (reader.Read())
                {
                    nodeType = reader.NodeType;
                    nodeName = reader.Name;
                    if (nodeType == XmlNodeType.Element)
                    {
                        switch (nodeName)
                        {
                        case "title":
                            nodeText = reader.ReadString().Trim();
                            if (!String.IsNullOrEmpty(nodeText))
                            {
                                _topicTitle = nodeText;
                            }
                            break;

                        case "tableOfContentsTitle":
                            nodeText = reader.ReadString().Trim();
                            if (!String.IsNullOrEmpty(nodeText))
                            {
                                _topicTocTitle = nodeText;
                            }
                            break;

                        case "linkText":
                            nodeText = reader.ReadString().Trim();
                            if (!String.IsNullOrEmpty(nodeText))
                            {
                                _topicLinkText = nodeText;
                            }
                            break;

                        case "keyword":
                            KeywordItem keyItem = new KeywordItem();
                            keyItem.ReadXml(reader);
                            if (!keyItem.IsEmpty)
                            {
                                _keywords.Add(keyItem);
                            }
                            break;

                        case "attribute":
                            AttributeItem attrItem = new AttributeItem();
                            attrItem.ReadXml(reader);
                            if (!attrItem.IsEmpty)
                            {
                                _attributes.Add(attrItem);
                            }
                            break;

                        case "authoring":
                            break;
                        }
                    }
                    else if (nodeType == XmlNodeType.EndElement)
                    {
                        if (String.Equals(nodeName, "metadata"))
                        {
                            this.OnDocumentType(nodeName);

                            break;
                        }
                    }
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(true);
        }