Example #1
0
        public static ExtensionElement ParseExtensionElement(XMLStreamReader xtr)
        {
            ExtensionElement extensionElement = CreateExtensionElement(xtr);

            bool readyWithExtensionElement = false;

            while (!readyWithExtensionElement && xtr.HasNext())
            {
                //xtr.next();

                if (xtr.NodeType == XmlNodeType.Text || xtr.NodeType == XmlNodeType.CDATA)
                {
                    if (!string.IsNullOrWhiteSpace(xtr.Value?.Trim()))
                    {
                        extensionElement.ElementText = xtr.Value?.Trim();
                    }
                }
                else if (xtr.IsStartElement())
                {
                    if (xtr.IsEmptyElement)
                    {
                        ExtensionElement childExtensionElement = CreateExtensionElement(xtr);
                        extensionElement.AddChildElement(childExtensionElement);
                        xtr.isEmpty = xtr.IsStartElement() && xtr.EndElement;
                        xtr.Next();
                        return(childExtensionElement);
                    }
                    else
                    {
                        ExtensionElement childExtensionElement = ParseExtensionElement(xtr);
                        extensionElement.AddChildElement(childExtensionElement);
                    }
                }
                else if (xtr.EndElement && string.Compare(extensionElement.Name, xtr.LocalName, true) == 0)
                {
                    readyWithExtensionElement = true;
                }

                if (xtr.IsEmptyElement && string.Compare(extensionElement.Name, xtr.LocalName, true) == 0)
                {
                    readyWithExtensionElement = true;
                }
            }
            return(extensionElement);
        }