private XmlEntityReference LoadEntityReferenceNode(bool direct) { Debug.Assert(_reader.NodeType == XmlNodeType.EntityReference); XmlEntityReference eref = direct ? new XmlEntityReference(_reader.Name, _doc) : _doc.CreateEntityReference(_reader.Name); if (_reader.CanResolveEntity) { _reader.ResolveEntity(); while (_reader.Read() && _reader.NodeType != XmlNodeType.EndEntity) { XmlNode node = direct ? LoadNodeDirect() : LoadNode(false); if (node != null) { eref.AppendChildForLoad(node, _doc); } } // 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 (eref.LastChild == null) { eref.AppendChildForLoad(_doc.CreateTextNode(string.Empty), _doc); } } return(eref); }
// Creates a duplicate of this node. public override XmlNode CloneNode(bool deep) { Debug.Assert(OwnerDocument != null); XmlEntityReference eref = OwnerDocument.CreateEntityReference(_name); return(eref); }
//The function is called when expanding the entity ref. ( inside XmlEntityReference.SetParent ) internal void ExpandEntityReference(XmlEntityReference eref) { //when the ent ref is not associated w/ an entity, append an empty string text node as child _doc = eref.OwnerDocument; bool bOrigLoadingState = _doc.IsLoading; _doc.IsLoading = true; switch (eref.Name) { case "lt": eref.AppendChildForLoad(_doc.CreateTextNode("<"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "gt": eref.AppendChildForLoad(_doc.CreateTextNode(">"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "amp": eref.AppendChildForLoad(_doc.CreateTextNode("&"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "apos": eref.AppendChildForLoad(_doc.CreateTextNode("'"), _doc); _doc.IsLoading = bOrigLoadingState; return; case "quot": eref.AppendChildForLoad(_doc.CreateTextNode("\""), _doc); _doc.IsLoading = bOrigLoadingState; return; } XmlNamedNodeMap entities = _doc.Entities; foreach (XmlEntity ent in entities) { if (Ref.Equal(ent.Name, eref.Name)) { ParsePartialContent(eref, EntitizeName(eref.Name), XmlNodeType.EntityReference); return; } } //no fit so far if (!(_doc.ActualLoadingStatus)) { eref.AppendChildForLoad(_doc.CreateTextNode(""), _doc); _doc.IsLoading = bOrigLoadingState; } else { _doc.IsLoading = bOrigLoadingState; throw new XmlException(ResXml.Xml_UndeclaredParEntity, eref.Name); } }