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); }
private XmlAttribute LoadAttributeNode() { XmlReader reader = this.reader; if (reader.IsDefault) { return(this.LoadDefaultAttribute()); } XmlAttribute attribute = this.doc.CreateAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI); IXmlSchemaInfo schemaInfo = reader.SchemaInfo; if (schemaInfo != null) { attribute.XmlName = this.doc.AddAttrXmlName(attribute.Prefix, attribute.LocalName, attribute.NamespaceURI, schemaInfo); } while (reader.ReadAttributeValue()) { XmlNode node; switch (reader.NodeType) { case XmlNodeType.Text: node = this.doc.CreateTextNode(reader.Value); break; case XmlNodeType.EntityReference: node = this.doc.CreateEntityReference(reader.LocalName); if (reader.CanResolveEntity) { reader.ResolveEntity(); this.LoadAttributeValue(node, false); if (node.FirstChild == null) { node.AppendChildForLoad(this.doc.CreateTextNode(string.Empty), this.doc); } } break; default: throw UnexpectedNodeType(reader.NodeType); } attribute.AppendChildForLoad(node, this.doc); } return(attribute); }