internal XmlNamespaceManager ParsePartialContent(XmlNode parentNode, string innerxmltext, XmlNodeType nt) { this.doc = parentNode.OwnerDocument; XmlParserContext context = this.GetContext(parentNode); this.reader = this.CreateInnerXmlReader(innerxmltext, nt, context, this.doc); try { this.preserveWhitespace = true; bool isLoading = this.doc.IsLoading; this.doc.IsLoading = true; if (nt == XmlNodeType.Entity) { XmlNode newChild = null; while (this.reader.Read() && ((newChild = this.LoadNodeDirect()) != null)) { parentNode.AppendChildForLoad(newChild, this.doc); } } else { XmlNode node2 = null; while (this.reader.Read() && ((node2 = this.LoadNode(true)) != null)) { parentNode.AppendChildForLoad(node2, this.doc); } } this.doc.IsLoading = isLoading; } finally { this.reader.Close(); } return(context.NamespaceManager); }
private void LoadAttributeValue(XmlNode parent, bool direct) { XmlReader reader = this.reader; while (reader.ReadAttributeValue()) { XmlNode node; switch (reader.NodeType) { case XmlNodeType.Text: node = direct ? new XmlText(reader.Value, this.doc) : this.doc.CreateTextNode(reader.Value); break; case XmlNodeType.EntityReference: node = direct ? new XmlEntityReference(this.reader.LocalName, this.doc) : this.doc.CreateEntityReference(this.reader.LocalName); if (reader.CanResolveEntity) { reader.ResolveEntity(); this.LoadAttributeValue(node, direct); if (node.FirstChild == null) { node.AppendChildForLoad(direct ? new XmlText(string.Empty) : this.doc.CreateTextNode(string.Empty), this.doc); } } break; case XmlNodeType.EndEntity: return; default: throw UnexpectedNodeType(reader.NodeType); } parent.AppendChildForLoad(node, this.doc); } }
private void LoadEntityChildren(XmlNode parent) { Debug.Assert(parent != null); XmlNode node = null; while (reader.Read() && (node = LoadEntityChildren()) != null) { parent.AppendChildForLoad(node, doc); } }
internal XmlNamespaceManager ParsePartialContent(XmlNode parentNode, string innerxmltext, XmlNodeType nt) { //the function shouldn't be used to set innerxml for XmlDocument node Debug.Assert(parentNode.NodeType != XmlNodeType.Document); _doc = parentNode.OwnerDocument; Debug.Assert(_doc != null); XmlParserContext pc = GetContext(parentNode); _reader = CreateInnerXmlReader(innerxmltext, nt, pc, _doc); try { _preserveWhitespace = true; bool bOrigLoading = _doc.IsLoading; _doc.IsLoading = true; if (nt == XmlNodeType.Entity) { XmlNode?node = null; while (_reader.Read() && (node = LoadNodeDirect()) != null) { parentNode.AppendChildForLoad(node, _doc); } } else { XmlNode?node = null; while (_reader.Read() && (node = LoadNode(true)) != null) { parentNode.AppendChildForLoad(node, _doc); } } _doc.IsLoading = bOrigLoading; } finally { _reader.Close(); } return(pc.NamespaceManager !); }
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; }
// LoadNodeDirect does not use creator functions on XmlDocument. It is used loading nodes that are children of entity nodes, // because we do not want to let users extend these (if we would allow this, XmlDataDocument would have a problem, because // they do not know that those nodes should not be mapped). It can be also used for an optimized load path when if the // XmlDocument is not extended if XmlDocumentType and XmlDeclaration handling is added. private XmlNode LoadNodeDirect() { XmlReader r = _reader; XmlNode parent = null; do { XmlNode node = null; switch (r.NodeType) { case XmlNodeType.Element: bool fEmptyElement = _reader.IsEmptyElement; XmlElement element = new XmlElement(_reader.Prefix, _reader.LocalName, _reader.NamespaceURI, _doc); element.IsEmpty = fEmptyElement; if (_reader.MoveToFirstAttribute()) { XmlAttributeCollection attributes = element.Attributes; do { XmlAttribute attr = LoadAttributeNodeDirect(); attributes.Append(attr); // special case for load } while (r.MoveToNextAttribute()); } // recursively load all children. if (!fEmptyElement) { parent.AppendChildForLoad(element, _doc); parent = element; continue; } else { node = element; break; } case XmlNodeType.EndElement: Debug.Assert(parent.NodeType == XmlNodeType.Element); if (parent.ParentNode == null) { return(parent); } parent = parent.ParentNode; continue; case XmlNodeType.EntityReference: node = LoadEntityReferenceNode(true); break; case XmlNodeType.EndEntity: continue; case XmlNodeType.Attribute: node = LoadAttributeNodeDirect(); break; case XmlNodeType.SignificantWhitespace: node = new XmlSignificantWhitespace(_reader.Value, _doc); break; case XmlNodeType.Whitespace: if (_preserveWhitespace) { node = new XmlWhitespace(_reader.Value, _doc); } else { continue; } break; case XmlNodeType.Text: node = new XmlText(_reader.Value, _doc); break; case XmlNodeType.CDATA: node = new XmlCDataSection(_reader.Value, _doc); break; case XmlNodeType.ProcessingInstruction: node = new XmlProcessingInstruction(_reader.Name, _reader.Value, _doc); break; case XmlNodeType.Comment: node = new XmlComment(_reader.Value, _doc); break; default: throw UnexpectedNodeType(_reader.NodeType); } Debug.Assert(node != null); if (parent != null) { parent.AppendChildForLoad(node, _doc); } else { return(node); } }while (r.Read()); return(null); }
private XmlNode LoadNode(bool skipOverWhitespace) { XmlReader r = _reader; XmlNode parent = null; XmlElement element; IXmlSchemaInfo schemaInfo; do { XmlNode node = null; switch (r.NodeType) { case XmlNodeType.Element: bool fEmptyElement = r.IsEmptyElement; element = _doc.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI); element.IsEmpty = fEmptyElement; if (r.MoveToFirstAttribute()) { XmlAttributeCollection attributes = element.Attributes; do { XmlAttribute attr = LoadAttributeNode(); attributes.Append(attr); // special case for load }while (r.MoveToNextAttribute()); r.MoveToElement(); } // recursively load all children. if (!fEmptyElement) { if (parent != null) { parent.AppendChildForLoad(element, _doc); } parent = element; continue; } else { schemaInfo = r.SchemaInfo; if (schemaInfo != null) { element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } node = element; break; } case XmlNodeType.EndElement: if (parent == null) { return(null); } Debug.Assert(parent.NodeType == XmlNodeType.Element); schemaInfo = r.SchemaInfo; if (schemaInfo != null) { element = parent as XmlElement; if (element != null) { element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } } if (parent.ParentNode == null) { return(parent); } parent = parent.ParentNode; continue; case XmlNodeType.EntityReference: node = LoadEntityReferenceNode(false); break; case XmlNodeType.EndEntity: Debug.Assert(parent == null); return(null); case XmlNodeType.Attribute: node = LoadAttributeNode(); break; case XmlNodeType.Text: node = _doc.CreateTextNode(r.Value); break; case XmlNodeType.SignificantWhitespace: node = _doc.CreateSignificantWhitespace(r.Value); break; case XmlNodeType.Whitespace: if (_preserveWhitespace) { node = _doc.CreateWhitespace(r.Value); break; } else if (parent == null && !skipOverWhitespace) { // if called from LoadEntityReferenceNode, just return null return(null); } else { continue; } case XmlNodeType.CDATA: node = _doc.CreateCDataSection(r.Value); break; case XmlNodeType.XmlDeclaration: node = LoadDeclarationNode(); break; case XmlNodeType.ProcessingInstruction: node = _doc.CreateProcessingInstruction(r.Name, r.Value); break; case XmlNodeType.Comment: node = _doc.CreateComment(r.Value); break; case XmlNodeType.DocumentType: node = LoadDocumentTypeNode(); break; default: throw UnexpectedNodeType(r.NodeType); } Debug.Assert(node != null); if (parent != null) { parent.AppendChildForLoad(node, _doc); } else { return(node); } }while (r.Read()); // when the reader ended before full subtree is read, return whatever we have created so far if (parent != null) { while (parent.ParentNode != null) { parent = parent.ParentNode; } } return(parent); }
internal XmlNamespaceManager ParsePartialContent(XmlNode parentNode, string innerxmltext, XmlNodeType nt) { //the function shouldn't be used to set innerxml for XmlDocument node Debug.Assert(parentNode.NodeType != XmlNodeType.Document); _doc = parentNode.OwnerDocument; Debug.Assert(_doc != null); XmlParserContext pc = GetContext(parentNode); _reader = CreateInnerXmlReader(innerxmltext, nt, pc, _doc); try { _preserveWhitespace = true; bool bOrigLoading = _doc.IsLoading; _doc.IsLoading = true; if (nt == XmlNodeType.Entity) { XmlNode node = null; while (_reader.Read() && (node = LoadNodeDirect()) != null) { parentNode.AppendChildForLoad(node, _doc); } } else { XmlNode node = null; while (_reader.Read() && (node = LoadNode(true)) != null) { parentNode.AppendChildForLoad(node, _doc); } } _doc.IsLoading = bOrigLoading; } finally { _reader.Dispose(); } return pc.NamespaceManager; }
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; }
private XmlNode LoadNodeDirect() { XmlNode node2; XmlReader reader = this.reader; XmlNode parentNode = null; Label_0009: node2 = null; switch (reader.NodeType) { case XmlNodeType.Element: { bool isEmptyElement = this.reader.IsEmptyElement; XmlElement newChild = new XmlElement(this.reader.Prefix, this.reader.LocalName, this.reader.NamespaceURI, this.doc) { IsEmpty = isEmptyElement }; if (this.reader.MoveToFirstAttribute()) { XmlAttributeCollection attributes = newChild.Attributes; do { XmlAttribute attribute = this.LoadAttributeNodeDirect(); attributes.Append(attribute); }while (reader.MoveToNextAttribute()); } if (!isEmptyElement) { parentNode.AppendChildForLoad(newChild, this.doc); parentNode = newChild; goto Label_01FC; } node2 = newChild; break; } case XmlNodeType.Attribute: node2 = this.LoadAttributeNodeDirect(); break; case XmlNodeType.Text: node2 = new XmlText(this.reader.Value, this.doc); break; case XmlNodeType.CDATA: node2 = new XmlCDataSection(this.reader.Value, this.doc); break; case XmlNodeType.EntityReference: node2 = this.LoadEntityReferenceNode(true); break; case XmlNodeType.ProcessingInstruction: node2 = new XmlProcessingInstruction(this.reader.Name, this.reader.Value, this.doc); break; case XmlNodeType.Comment: node2 = new XmlComment(this.reader.Value, this.doc); break; case XmlNodeType.Whitespace: if (!this.preserveWhitespace) { goto Label_01FC; } node2 = new XmlWhitespace(this.reader.Value, this.doc); break; case XmlNodeType.SignificantWhitespace: node2 = new XmlSignificantWhitespace(this.reader.Value, this.doc); break; case XmlNodeType.EndElement: if (parentNode.ParentNode != null) { parentNode = parentNode.ParentNode; goto Label_01FC; } return(parentNode); case XmlNodeType.EndEntity: goto Label_01FC; default: throw UnexpectedNodeType(this.reader.NodeType); } if (parentNode != null) { parentNode.AppendChildForLoad(node2, this.doc); } else { return(node2); } Label_01FC: if (reader.Read()) { goto Label_0009; } return(null); }
private XmlNode LoadNode(bool skipOverWhitespace) { XmlElement element; IXmlSchemaInfo schemaInfo; XmlNode node2; XmlReader reader = this.reader; XmlNode parentNode = null; Label_0009: node2 = null; switch (reader.NodeType) { case XmlNodeType.Element: { bool isEmptyElement = reader.IsEmptyElement; element = this.doc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); element.IsEmpty = isEmptyElement; if (reader.MoveToFirstAttribute()) { XmlAttributeCollection attributes = element.Attributes; do { XmlAttribute attribute = this.LoadAttributeNode(); attributes.Append(attribute); }while (reader.MoveToNextAttribute()); reader.MoveToElement(); } if (isEmptyElement) { schemaInfo = reader.SchemaInfo; if (schemaInfo != null) { element.XmlName = this.doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } node2 = element; break; } if (parentNode != null) { parentNode.AppendChildForLoad(element, this.doc); } parentNode = element; goto Label_025B; } case XmlNodeType.Attribute: node2 = this.LoadAttributeNode(); break; case XmlNodeType.Text: node2 = this.doc.CreateTextNode(reader.Value); break; case XmlNodeType.CDATA: node2 = this.doc.CreateCDataSection(reader.Value); break; case XmlNodeType.EntityReference: node2 = this.LoadEntityReferenceNode(false); break; case XmlNodeType.ProcessingInstruction: node2 = this.doc.CreateProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.Comment: node2 = this.doc.CreateComment(reader.Value); break; case XmlNodeType.DocumentType: node2 = this.LoadDocumentTypeNode(); break; case XmlNodeType.Whitespace: if (!this.preserveWhitespace) { if ((parentNode == null) && !skipOverWhitespace) { return(null); } goto Label_025B; } node2 = this.doc.CreateWhitespace(reader.Value); break; case XmlNodeType.SignificantWhitespace: node2 = this.doc.CreateSignificantWhitespace(reader.Value); break; case XmlNodeType.EndElement: if (parentNode != null) { schemaInfo = reader.SchemaInfo; if (schemaInfo != null) { element = parentNode as XmlElement; if (element != null) { element.XmlName = this.doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo); } } if (parentNode.ParentNode == null) { return(parentNode); } parentNode = parentNode.ParentNode; goto Label_025B; } return(null); case XmlNodeType.EndEntity: return(null); case XmlNodeType.XmlDeclaration: node2 = this.LoadDeclarationNode(); break; default: throw UnexpectedNodeType(reader.NodeType); } if (parentNode != null) { parentNode.AppendChildForLoad(node2, this.doc); } else { return(node2); } Label_025B: if (reader.Read()) { goto Label_0009; } if (parentNode != null) { while (parentNode.ParentNode != null) { parentNode = parentNode.ParentNode; } } return(parentNode); }
// The way it is getting called guarantees that the reader is pointing at an element node or entity node, or the reader is // at Initial status. In this cases, LoadChildren will stop when nodes in the lower level are all consumed. private void LoadChildren( XmlNode parent ) { Debug.Assert( parent != null ); XmlNode node = null; while ( reader.Read() && (node = LoadCurrentNode()) != null ) { parent.AppendChildForLoad( node, doc ); } }
internal XmlNamespaceManager ParsePartialContent(XmlNode parentNode, string innerxmltext, XmlNodeType nt) { this.doc = parentNode.OwnerDocument; XmlParserContext context = this.GetContext(parentNode); this.reader = this.CreateInnerXmlReader(innerxmltext, nt, context, this.doc); try { this.preserveWhitespace = true; bool isLoading = this.doc.IsLoading; this.doc.IsLoading = true; if (nt == XmlNodeType.Entity) { XmlNode newChild = null; while (this.reader.Read() && ((newChild = this.LoadNodeDirect()) != null)) { parentNode.AppendChildForLoad(newChild, this.doc); } } else { XmlNode node2 = null; while (this.reader.Read() && ((node2 = this.LoadNode(true)) != null)) { parentNode.AppendChildForLoad(node2, this.doc); } } this.doc.IsLoading = isLoading; } finally { this.reader.Close(); } return context.NamespaceManager; }
private void LoadAttributeValue(XmlNode parent, bool direct) { XmlReader reader = this.reader; while (reader.ReadAttributeValue()) { XmlNode node; switch (reader.NodeType) { case XmlNodeType.Text: node = direct ? new XmlText(reader.Value, this.doc) : this.doc.CreateTextNode(reader.Value); break; case XmlNodeType.EntityReference: node = direct ? new XmlEntityReference(this.reader.LocalName, this.doc) : this.doc.CreateEntityReference(this.reader.LocalName); if (reader.CanResolveEntity) { reader.ResolveEntity(); this.LoadAttributeValue(node, direct); if (node.FirstChild == null) { node.AppendChildForLoad(direct ? new XmlText(string.Empty) : this.doc.CreateTextNode(string.Empty), this.doc); } } break; case XmlNodeType.EndEntity: return; default: throw UnexpectedNodeType(reader.NodeType); } parent.AppendChildForLoad(node, this.doc); } }