System.Xml.XmlLoader.ExpandEntityReference C# (CSharp) Méthode

ExpandEntityReference() private méthode

private ExpandEntityReference ( XmlEntityReference eref ) : void
eref XmlEntityReference
Résultat void
        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(SR.Xml_UndeclaredParEntity, eref.Name);
            }
        }

Usage Example

 internal override void SetParent(XmlNode?node)
 {
     base.SetParent(node);
     if (LastNode == null && node != null && node != OwnerDocument)
     {
         //first time insert the entity reference into the tree, we should expand its children now
         XmlLoader loader = new XmlLoader();
         loader.ExpandEntityReference(this);
     }
 }
All Usage Examples Of System.Xml.XmlLoader::ExpandEntityReference