private void MoveNextInXml(XmlDataNode dataNode)
 {
     if (this.IsXmlDataNode)
     {
         this.xmlNodeReader.Read();
         if (this.xmlNodeReader.Depth == 0)
         {
             this.internalNodeType = ExtensionDataNodeType.EndElement;
             this.xmlNodeReader    = null;
         }
     }
     else
     {
         this.internalNodeType = ExtensionDataNodeType.Xml;
         if (this.element == null)
         {
             this.element = this.nextElement;
         }
         else
         {
             this.PushElement();
         }
         System.Xml.XmlNode node = XmlObjectSerializerReadContext.CreateWrapperXmlElement(dataNode.OwnerDocument, dataNode.XmlAttributes, dataNode.XmlChildNodes, this.element.prefix, this.element.localName, this.element.ns);
         for (int i = 0; i < this.element.attributeCount; i++)
         {
             AttributeData           data      = this.element.attributes[i];
             System.Xml.XmlAttribute attribute = dataNode.OwnerDocument.CreateAttribute(data.prefix, data.localName, data.ns);
             attribute.Value = data.value;
             node.Attributes.Append(attribute);
         }
         this.xmlNodeReader = new XmlNodeReader(node);
         this.xmlNodeReader.Read();
     }
 }
        private IDataNode ReadUnknownXmlData(XmlReaderDelegator xmlReader, string?dataContractName, string?dataContractNamespace)
        {
            XmlDataNode dataNode = new XmlDataNode();

            InitializeExtensionDataNode(dataNode, dataContractName, dataContractNamespace);
            dataNode.OwnerDocument = Document;

            if (xmlReader.NodeType == XmlNodeType.EndElement)
            {
                return(dataNode);
            }

            IList <XmlAttribute>?xmlAttributes = null;
            IList <XmlNode>?     xmlChildNodes = null;

            XmlNodeType nodeType = xmlReader.MoveToContent();

            if (nodeType != XmlNodeType.Text)
            {
                while (xmlReader.MoveToNextAttribute())
                {
                    string ns = xmlReader.NamespaceURI;
                    if (ns != Globals.SerializationNamespace && ns != Globals.SchemaInstanceNamespace)
                    {
                        if (xmlAttributes == null)
                        {
                            xmlAttributes = new List <XmlAttribute>();
                        }
                        xmlAttributes.Add((XmlAttribute)Document.ReadNode(xmlReader.UnderlyingReader) !);
                    }
                }
                Read(xmlReader);
            }

            while ((nodeType = xmlReader.MoveToContent()) != XmlNodeType.EndElement)
            {
                if (xmlReader.EOF)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
                }

                if (xmlChildNodes == null)
                {
                    xmlChildNodes = new List <XmlNode>();
                }
                xmlChildNodes.Add(Document.ReadNode(xmlReader.UnderlyingReader) !);
            }
            xmlReader.ReadEndElement();

            dataNode.XmlAttributes = xmlAttributes;
            dataNode.XmlChildNodes = xmlChildNodes;
            return(dataNode);
        }
예제 #3
0
        private IDataNode ReadUnknownXmlData(XmlReaderDelegator xmlReader, string dataContractName, string dataContractNamespace)
        {
            XmlDataNode dataNode = new XmlDataNode();

            this.InitializeExtensionDataNode(dataNode, dataContractName, dataContractNamespace);
            dataNode.OwnerDocument = this.Document;
            if (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                IList <System.Xml.XmlAttribute> list  = null;
                IList <System.Xml.XmlNode>      list2 = null;
                if (xmlReader.MoveToContent() != XmlNodeType.Text)
                {
                    while (xmlReader.MoveToNextAttribute())
                    {
                        string namespaceURI = xmlReader.NamespaceURI;
                        if ((namespaceURI != "http://schemas.microsoft.com/2003/10/Serialization/") && (namespaceURI != "http://www.w3.org/2001/XMLSchema-instance"))
                        {
                            if (list == null)
                            {
                                list = new List <System.Xml.XmlAttribute>();
                            }
                            list.Add((System.Xml.XmlAttribute) this.Document.ReadNode(xmlReader.UnderlyingReader));
                        }
                    }
                    Read(xmlReader);
                }
                while (xmlReader.MoveToContent() != XmlNodeType.EndElement)
                {
                    if (xmlReader.EOF)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("UnexpectedEndOfFile")));
                    }
                    if (list2 == null)
                    {
                        list2 = new List <System.Xml.XmlNode>();
                    }
                    list2.Add(this.Document.ReadNode(xmlReader.UnderlyingReader));
                }
                xmlReader.ReadEndElement();
                dataNode.XmlAttributes = list;
                dataNode.XmlChildNodes = list2;
            }
            return(dataNode);
        }
 private void WriteExtensionXmlData(XmlWriterDelegator xmlWriter, XmlDataNode dataNode)
 {
     if (!this.TryWriteDeserializedExtensionData(xmlWriter, dataNode))
     {
         IList <System.Xml.XmlAttribute> xmlAttributes = dataNode.XmlAttributes;
         if (xmlAttributes != null)
         {
             foreach (System.Xml.XmlAttribute attribute in xmlAttributes)
             {
                 attribute.WriteTo(xmlWriter.Writer);
             }
         }
         this.WriteExtensionDataTypeInfo(xmlWriter, dataNode);
         IList <System.Xml.XmlNode> xmlChildNodes = dataNode.XmlChildNodes;
         if (xmlChildNodes != null)
         {
             foreach (System.Xml.XmlNode node in xmlChildNodes)
             {
                 node.WriteTo(xmlWriter.Writer);
             }
         }
     }
 }
예제 #5
0
        void MoveNextInXml(XmlDataNode dataNode)
        {
            if (IsXmlDataNode)
            {
                xmlNodeReader.Read();
                if (xmlNodeReader.Depth == 0)
                {
                    this.internalNodeType = ExtensionDataNodeType.EndElement;
                    xmlNodeReader         = null;
                }
            }
            else
            {
                internalNodeType = ExtensionDataNodeType.Xml;
                if (element == null)
                {
                    element = nextElement;
                }
                else
                {
                    PushElement();
                }

                XmlNode wrapperElement = XmlObjectSerializerReadContext.CreateWrapperXmlElement(dataNode.OwnerDocument,
                                                                                                dataNode.XmlAttributes, dataNode.XmlChildNodes, element.prefix, element.localName, element.ns);
                for (int i = 0; i < element.attributeCount; i++)
                {
                    AttributeData a       = element.attributes[i];
                    XmlAttribute  xmlAttr = dataNode.OwnerDocument.CreateAttribute(a.prefix, a.localName, a.ns);
                    xmlAttr.Value = a.value;
                    wrapperElement.Attributes.Append(xmlAttr);
                }
                xmlNodeReader = new XmlNodeReader(wrapperElement);
                xmlNodeReader.Read();
            }
        }
예제 #6
0
        private IDataNode ReadAndResolveUnknownXmlData(XmlReaderDelegator xmlReader, IDictionary <string, string> namespaces, string dataContractName, string dataContractNamespace)
        {
            XmlNodeType type;
            bool        flag  = true;
            bool        flag2 = true;
            bool        flag3 = true;
            string      strA  = null;
            string      str2  = null;
            IList <System.Xml.XmlNode>      xmlChildNodes = new List <System.Xml.XmlNode>();
            IList <System.Xml.XmlAttribute> xmlAttributes = null;

            if (namespaces != null)
            {
                xmlAttributes = new List <System.Xml.XmlAttribute>();
                foreach (KeyValuePair <string, string> pair in namespaces)
                {
                    xmlAttributes.Add(this.AddNamespaceDeclaration(pair.Key, pair.Value));
                }
            }
            while ((type = xmlReader.NodeType) != XmlNodeType.EndElement)
            {
                if (type == XmlNodeType.Element)
                {
                    string namespaceURI = xmlReader.NamespaceURI;
                    string localName    = xmlReader.LocalName;
                    if (flag)
                    {
                        flag = namespaceURI.Length == 0;
                    }
                    if (flag2)
                    {
                        if (str2 == null)
                        {
                            str2 = localName;
                            strA = namespaceURI;
                        }
                        else
                        {
                            flag2 = (string.CompareOrdinal(str2, localName) == 0) && (string.CompareOrdinal(strA, namespaceURI) == 0);
                        }
                    }
                }
                else
                {
                    if (xmlReader.EOF)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(System.Runtime.Serialization.SR.GetString("UnexpectedEndOfFile")));
                    }
                    if (this.IsContentNode(xmlReader.NodeType))
                    {
                        flag3 = flag = flag2 = false;
                    }
                }
                if (this.attributesInXmlData == null)
                {
                    this.attributesInXmlData = new Attributes();
                }
                this.attributesInXmlData.Read(xmlReader);
                System.Xml.XmlNode item = this.Document.ReadNode(xmlReader.UnderlyingReader);
                xmlChildNodes.Add(item);
                if (namespaces == null)
                {
                    if (this.attributesInXmlData.XsiTypeName != null)
                    {
                        item.Attributes.Append(this.AddNamespaceDeclaration(this.attributesInXmlData.XsiTypePrefix, this.attributesInXmlData.XsiTypeNamespace));
                    }
                    if (this.attributesInXmlData.FactoryTypeName != null)
                    {
                        item.Attributes.Append(this.AddNamespaceDeclaration(this.attributesInXmlData.FactoryTypePrefix, this.attributesInXmlData.FactoryTypeNamespace));
                    }
                }
            }
            xmlReader.ReadEndElement();
            if ((str2 != null) && flag2)
            {
                return(this.ReadUnknownCollectionData(this.CreateReaderOverChildNodes(xmlAttributes, xmlChildNodes), dataContractName, dataContractNamespace));
            }
            if (flag)
            {
                return(this.ReadUnknownISerializableData(this.CreateReaderOverChildNodes(xmlAttributes, xmlChildNodes), dataContractName, dataContractNamespace));
            }
            if (flag3)
            {
                return(this.ReadUnknownClassData(this.CreateReaderOverChildNodes(xmlAttributes, xmlChildNodes), dataContractName, dataContractNamespace));
            }
            XmlDataNode dataNode = new XmlDataNode();

            this.InitializeExtensionDataNode(dataNode, dataContractName, dataContractNamespace);
            dataNode.OwnerDocument = this.Document;
            dataNode.XmlChildNodes = xmlChildNodes;
            dataNode.XmlAttributes = xmlAttributes;
            return(dataNode);
        }
        private IDataNode ReadAndResolveUnknownXmlData(XmlReaderDelegator xmlReader, IDictionary <string, string>?namespaces,
                                                       string?dataContractName, string?dataContractNamespace)
        {
            bool   couldBeISerializableData = true;
            bool   couldBeCollectionData = true;
            bool   couldBeClassData = true;
            string?elementNs = null, elementName = null;
            var    xmlChildNodes               = new List <XmlNode>();
            IList <XmlAttribute>?xmlAttributes = null;

            if (namespaces != null)
            {
                xmlAttributes = new List <XmlAttribute>();
                foreach (KeyValuePair <string, string> prefixNsPair in namespaces)
                {
                    xmlAttributes.Add(AddNamespaceDeclaration(prefixNsPair.Key, prefixNsPair.Value));
                }
            }

            XmlNodeType nodeType;

            while ((nodeType = xmlReader.NodeType) != XmlNodeType.EndElement)
            {
                if (nodeType == XmlNodeType.Element)
                {
                    string ns   = xmlReader.NamespaceURI;
                    string name = xmlReader.LocalName;
                    if (couldBeISerializableData)
                    {
                        couldBeISerializableData = (ns.Length == 0);
                    }
                    if (couldBeCollectionData)
                    {
                        if (elementName == null)
                        {
                            elementName = name;
                            elementNs   = ns;
                        }
                        else
                        {
                            couldBeCollectionData = (string.CompareOrdinal(elementName, name) == 0) &&
                                                    (string.CompareOrdinal(elementNs, ns) == 0);
                        }
                    }
                }
                else if (xmlReader.EOF)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.UnexpectedEndOfFile));
                }
                else if (IsContentNode(xmlReader.NodeType))
                {
                    couldBeClassData = couldBeISerializableData = couldBeCollectionData = false;
                }

                _attributesInXmlData ??= new Attributes();
                _attributesInXmlData.Read(xmlReader);

                XmlNode childNode = Document.ReadNode(xmlReader.UnderlyingReader) !;
                xmlChildNodes.Add(childNode);

                if (namespaces == null)
                {
                    if (_attributesInXmlData.XsiTypeName != null)
                    {
                        childNode.Attributes !.Append(AddNamespaceDeclaration(_attributesInXmlData.XsiTypePrefix, _attributesInXmlData.XsiTypeNamespace));
                    }
                    if (_attributesInXmlData.FactoryTypeName != null)
                    {
                        childNode.Attributes !.Append(AddNamespaceDeclaration(_attributesInXmlData.FactoryTypePrefix, _attributesInXmlData.FactoryTypeNamespace));
                    }
                }
            }
            xmlReader.ReadEndElement();

            if (elementName != null && couldBeCollectionData)
            {
                return(ReadUnknownCollectionData(CreateReaderOverChildNodes(xmlAttributes, xmlChildNodes), dataContractName, dataContractNamespace));
            }
            else if (couldBeISerializableData)
            {
                return(ReadUnknownISerializableData(CreateReaderOverChildNodes(xmlAttributes, xmlChildNodes), dataContractName, dataContractNamespace));
            }
            else if (couldBeClassData)
            {
                return(ReadUnknownClassData(CreateReaderOverChildNodes(xmlAttributes, xmlChildNodes), dataContractName, dataContractNamespace));
            }
            else
            {
                XmlDataNode dataNode = new XmlDataNode();
                InitializeExtensionDataNode(dataNode, dataContractName, dataContractNamespace);
                dataNode.OwnerDocument = Document;
                dataNode.XmlChildNodes = xmlChildNodes;
                dataNode.XmlAttributes = xmlAttributes;
                return(dataNode);
            }
        }