Esempio n. 1
0
        private XmlAttribute LoadAttributeNode()
        {
            Debug.Assert(_reader.NodeType == XmlNodeType.Attribute);

            XmlReader r = _reader;

            if (r.IsDefault)
            {
                return(LoadDefaultAttribute());
            }

            XmlAttribute   attr       = _doc.CreateAttribute(r.Prefix, r.LocalName, r.NamespaceURI);
            IXmlSchemaInfo schemaInfo = r.SchemaInfo;

            if (schemaInfo != null)
            {
                attr.XmlName = _doc.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, schemaInfo);
            }
            while (r.ReadAttributeValue())
            {
                XmlNode node;
                switch (r.NodeType)
                {
                case XmlNodeType.Text:
                    node = _doc.CreateTextNode(r.Value);
                    break;

                case XmlNodeType.EntityReference:
                    node = _doc.CreateEntityReference(r.LocalName);
                    if (r.CanResolveEntity)
                    {
                        r.ResolveEntity();
                        LoadAttributeValue(node, false);
                        // Code internally relies on the fact that an EntRef nodes has at least one child (even an empty text node). Ensure that this holds true,
                        // if the reader does not present any children for the ent-ref
                        if (node.FirstChild == null)
                        {
                            node.AppendChildForLoad(_doc.CreateTextNode(string.Empty), _doc);
                        }
                    }
                    break;

                default:
                    throw UnexpectedNodeType(r.NodeType);
                }
                Debug.Assert(node != null);
                attr.AppendChildForLoad(node, _doc);
            }

            return(attr);
        }
 // Iterates through the current attribute value's text and entity references chunks.
 public override bool ReadAttributeValue()
 {
     if (_parsingFunction == ParsingFunction.InReadBinaryContent)
     {
         _parsingFunction = ParsingFunction.Read;
         _readBinaryHelper.Finish();
     }
     if (!_coreReader.ReadAttributeValue())
     {
         return(false);
     }
     _parsingFunction = ParsingFunction.Read;
     return(true);
 }
Esempio n. 3
0
        // XmlReader Helper Methods

        // Writes out all the attributes found at the current position in the specified XmlReader.
        public virtual void WriteAttributes(XmlReader reader, bool defattr)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.XmlDeclaration)
            {
                if (reader.MoveToFirstAttribute())
                {
                    WriteAttributes(reader, defattr);
                    reader.MoveToElement();
                }
            }
            else if (reader.NodeType != XmlNodeType.Attribute)
            {
                throw new XmlException(ResXml.Xml_InvalidPosition, string.Empty);
            }
            else
            {
                do
                {
                    // we need to check both XmlReader.IsDefault and XmlReader.SchemaInfo.IsDefault.
                    // If either of these is true and defattr=false, we should not write the attribute out
                    if (defattr || !reader.IsDefaultInternal)
                    {
                        WriteStartAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                        while (reader.ReadAttributeValue())
                        {
                            if (reader.NodeType == XmlNodeType.EntityReference)
                            {
                                WriteEntityRef(reader.Name);
                            }
                            else
                            {
                                WriteString(reader.Value);
                            }
                        }
                        WriteEndAttribute();
                    }
                }while (reader.MoveToNextAttribute());
            }
        }
Esempio n. 4
0
        private void LoadAttributeValue(XmlNode parent, bool direct)
        {
            XmlReader r = _reader;

            while (r.ReadAttributeValue())
            {
                XmlNode node;
                switch (r.NodeType)
                {
                case XmlNodeType.Text:
                    node = direct ? new XmlText(r.Value, _doc) : _doc.CreateTextNode(r.Value);
                    break;

                case XmlNodeType.EndEntity:
                    return;

                case XmlNodeType.EntityReference:
                    node = direct ? new XmlEntityReference(_reader.LocalName, _doc) : _doc.CreateEntityReference(_reader.LocalName);
                    if (r.CanResolveEntity)
                    {
                        r.ResolveEntity();
                        LoadAttributeValue(node, direct);
                        // Code internally relies on the fact that an EntRef nodes has at least one child (even an empty text node). Ensure that this holds true,
                        // if the reader does not present any children for the ent-ref
                        if (node.FirstChild == null)
                        {
                            node.AppendChildForLoad(direct ? new XmlText(string.Empty) : _doc.CreateTextNode(string.Empty), _doc);
                        }
                    }
                    break;

                default:
                    throw UnexpectedNodeType(r.NodeType);
                }
                Debug.Assert(node != null);
                parent.AppendChildForLoad(node, _doc);
            }
            return;
        }
Esempio n. 5
0
 public override bool ReadAttributeValue()
 {
     return(reader.ReadAttributeValue());
 }
Esempio n. 6
0
 public override bool ReadAttributeValue()
 {
     CheckAsync();
     return(_coreReader.ReadAttributeValue());
 }