示例#1
0
        /// <inheritdoc/>
        internal override void Populate(XmlReader xmlReader, OpenXmlLoadMode loadMode)
        {
            if (string.IsNullOrEmpty(_tagName))
            {
                _tagName      = xmlReader.LocalName;
                _prefix       = xmlReader.Prefix;
                _namespaceUri = xmlReader.NamespaceURI;
            }
            else
            {
                Debug.Assert(string.Equals(_tagName, xmlReader.LocalName));
                Debug.Assert(string.Equals(_prefix, xmlReader.Prefix));
                Debug.Assert(string.Equals(_namespaceUri, xmlReader.NamespaceURI));
            }

            // load children elements
            base.Populate(xmlReader, loadMode);

            if (FirstChild != null && FirstChild.NextSibling() == null)
            {
                // only one child
                OpenXmlMiscNode miscNode = FirstChild as OpenXmlMiscNode;
                if (miscNode != null)
                {
                    switch (miscNode.XmlNodeType)
                    {
                    case XmlNodeType.Text:
                    case XmlNodeType.CDATA:
                    case XmlNodeType.SignificantWhitespace:
                        _text = miscNode.OuterXml;     // is this OK?
                        RemoveChild(miscNode);
                        break;

                    case XmlNodeType.Whitespace:     // O15:#3024890, OpenXmlUnknownElement ignores the Whitespace NodeType.
                    default:
                        break;
                    }
                }
            }
        }