Inheritance: XmlLinkedNode, IHasXmlChildNode
        // Creates a duplicate of this node.
        public override XmlNode CloneNode(bool deep)
        {
            Debug.Assert(OwnerDocument != null);
            XmlEntityReference eref = OwnerDocument.CreateEntityReference(_name);

            return(eref);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        private void LoadEntityAttributeChildren(XmlNode parent)
        {
            while (reader.ReadAttributeValue())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.EndEntity:
                    // exit read loop
                    return;

                case XmlNodeType.Text:
                    parent.AppendChild(new XmlText(reader.Value, this.doc));
                    break;

                case XmlNodeType.EntityReference: {
                    XmlEntityReference eref = new XmlEntityReference(reader.LocalName, this.doc);
                    reader.ResolveEntity();
                    LoadEntityAttributeChildren(eref);
                    //what if eref doesn't have children at all? should we just put a Empty String text here?
                    if (eref.ChildNodes.Count == 0)
                    {
                        eref.AppendChild(new XmlText(""));
                    }
                    parent.AppendChild(eref);
                    break;
                }

                default:
                    throw new InvalidOperationException(Res.GetString(Res.Xdom_Load_NodeType) + reader.NodeType);
                }
            }
        }
Beispiel #4
0
        //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(SR.Xml_UndeclaredParEntity, eref.Name);
            }
        }
Beispiel #5
0
        internal void ExpandEntityReference(XmlEntityReference eref)
        {
            this.doc = eref.OwnerDocument;
            bool isLoading = this.doc.IsLoading;

            this.doc.IsLoading = true;
            switch (eref.Name)
            {
            case "lt":
                eref.AppendChildForLoad(this.doc.CreateTextNode("<"), this.doc);
                this.doc.IsLoading = isLoading;
                return;

            case "gt":
                eref.AppendChildForLoad(this.doc.CreateTextNode(">"), this.doc);
                this.doc.IsLoading = isLoading;
                return;

            case "amp":
                eref.AppendChildForLoad(this.doc.CreateTextNode("&"), this.doc);
                this.doc.IsLoading = isLoading;
                return;

            case "apos":
                eref.AppendChildForLoad(this.doc.CreateTextNode("'"), this.doc);
                this.doc.IsLoading = isLoading;
                return;

            case "quot":
                eref.AppendChildForLoad(this.doc.CreateTextNode("\""), this.doc);
                this.doc.IsLoading = isLoading;
                return;
            }
            foreach (XmlEntity entity in this.doc.Entities)
            {
                if (Ref.Equal(entity.Name, eref.Name))
                {
                    this.ParsePartialContent(eref, this.EntitizeName(eref.Name), XmlNodeType.EntityReference);
                    return;
                }
            }
            if (!this.doc.ActualLoadingStatus)
            {
                eref.AppendChildForLoad(this.doc.CreateTextNode(""), this.doc);
                this.doc.IsLoading = isLoading;
            }
            else
            {
                this.doc.IsLoading = isLoading;
                throw new XmlException("Xml_UndeclaredParEntity", eref.Name);
            }
        }
        internal void ExpandEntityReference(XmlEntityReference eref)
        {
            this.doc = eref.OwnerDocument;
            bool isLoading = this.doc.IsLoading;
            this.doc.IsLoading = true;
            switch (eref.Name)
            {
                case "lt":
                    eref.AppendChildForLoad(this.doc.CreateTextNode("<"), this.doc);
                    this.doc.IsLoading = isLoading;
                    return;

                case "gt":
                    eref.AppendChildForLoad(this.doc.CreateTextNode(">"), this.doc);
                    this.doc.IsLoading = isLoading;
                    return;

                case "amp":
                    eref.AppendChildForLoad(this.doc.CreateTextNode("&"), this.doc);
                    this.doc.IsLoading = isLoading;
                    return;

                case "apos":
                    eref.AppendChildForLoad(this.doc.CreateTextNode("'"), this.doc);
                    this.doc.IsLoading = isLoading;
                    return;

                case "quot":
                    eref.AppendChildForLoad(this.doc.CreateTextNode("\""), this.doc);
                    this.doc.IsLoading = isLoading;
                    return;
            }
            foreach (XmlEntity entity in this.doc.Entities)
            {
                if (Ref.Equal(entity.Name, eref.Name))
                {
                    this.ParsePartialContent(eref, this.EntitizeName(eref.Name), XmlNodeType.EntityReference);
                    return;
                }
            }
            if (!this.doc.ActualLoadingStatus)
            {
                eref.AppendChildForLoad(this.doc.CreateTextNode(""), this.doc);
                this.doc.IsLoading = isLoading;
            }
            else
            {
                this.doc.IsLoading = isLoading;
                throw new XmlException("Xml_UndeclaredParEntity", eref.Name);
            }
        }
Beispiel #7
0
        private XmlEntityReference LoadEntityReferenceNode()
        {
            Debug.Assert(reader.NodeType == XmlNodeType.EntityReference);

            XmlEntityReference eref = doc.CreateEntityReference(reader.Name);

            if (reader.CanResolveEntity)
            {
                reader.ResolveEntity();
                LoadChildren(eref);
                // 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.AppendChild(doc.CreateTextNode(""));
                }
            }
            return(eref);
        }
Beispiel #8
0
        private XmlEntityReference LoadEntityReferenceNode(bool direct)
        {
            XmlEntityReference reference = direct ? new XmlEntityReference(this.reader.Name, this.doc) : this.doc.CreateEntityReference(this.reader.Name);

            if (this.reader.CanResolveEntity)
            {
                this.reader.ResolveEntity();
                while (this.reader.Read() && (this.reader.NodeType != XmlNodeType.EndEntity))
                {
                    XmlNode newChild = direct ? this.LoadNodeDirect() : this.LoadNode(false);
                    if (newChild != null)
                    {
                        reference.AppendChildForLoad(newChild, this.doc);
                    }
                }
                if (reference.LastChild == null)
                {
                    reference.AppendChildForLoad(this.doc.CreateTextNode(string.Empty), this.doc);
                }
            }
            return(reference);
        }
Beispiel #9
0
        //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(SR.Format(SR.Xml_UndeclaredParEntity, eref.Name));
            }
        }
Beispiel #10
0
        private void LoadEntityAttributeChildren( XmlNode parent ) {
            while (reader.ReadAttributeValue()) {
                switch (reader.NodeType) {
                    case XmlNodeType.EndEntity:
                        // exit read loop
                        return;

                    case XmlNodeType.Text:
                        parent.AppendChild( new XmlText( reader.Value, this.doc ) );
                        break;

                    case XmlNodeType.EntityReference: {
                        XmlEntityReference eref = new XmlEntityReference( reader.LocalName, this.doc );
                        reader.ResolveEntity();
                        LoadEntityAttributeChildren( eref );
                        //what if eref doesn't have children at all? should we just put a Empty String text here?
                        if ( eref.ChildNodes.Count == 0 )
                            eref.AppendChild( new XmlText("") );
                        parent.AppendChild( eref );
                        break;
                    }

                    default:
                        throw new InvalidOperationException(Res.GetString(Res.Xdom_Load_NodeType) + reader.NodeType);
                }
            }
        }
Beispiel #11
0
        private XmlNode LoadEntityChildren() {
            XmlNode node = null;

            // We do not use creator functions on XmlDocument, b/c we do not want to let users extend the nodes that are children of entity nodes (also, if we do
            // this, XmlDataDocument will have a problem, b/c they do not know that those nodes should not be mapped).
            switch (reader.NodeType) {
                case XmlNodeType.EndElement:
                case XmlNodeType.EndEntity:
                    break;

                case XmlNodeType.Element: {
                    bool fEmptyElement = reader.IsEmptyElement;

                    XmlElement element = new XmlElement( reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc );
                    element.IsEmpty = fEmptyElement;

                    while(reader.MoveToNextAttribute()) {
                        XmlAttribute attr = (XmlAttribute) LoadEntityChildren();
                        element.Attributes.Append( attr );
                    }

                    // recursively load all children.
                    if (! fEmptyElement)
                        LoadEntityChildren( element );

                    node = element;
                    break;
                }

                case XmlNodeType.Attribute:
                    if (reader.IsDefault) {
                        XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute( reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc );
                        LoadEntityAttributeChildren( attr );
                        attr.SetSpecified( false );
                        node = attr;
                    }
                    else {
                        XmlAttribute attr = new XmlAttribute( reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc );
                        LoadEntityAttributeChildren( attr );
                        node = attr;
                    }
                    break;

                case XmlNodeType.SignificantWhitespace:
                    node = new XmlSignificantWhitespace( reader.Value, this.doc );
                    break;

                case XmlNodeType.Whitespace:
                    if ( preserveWhitespace )
                        node = new XmlWhitespace( reader.Value, this.doc );
                    else {
                        // if preserveWhitespace is false skip all subsequent WS nodes and position on the first non-WS node
                        do {
                            if (! reader.Read() )
                                return null;
                        } while (reader.NodeType == XmlNodeType.Whitespace);
                        node = LoadEntityChildren();   // Skip WS node if preserveWhitespace is false
                    }
                    break;

                case XmlNodeType.Text:
                    node = new XmlText( reader.Value, this.doc );
                    break;

                case XmlNodeType.CDATA:
                    node = new XmlCDataSection( reader.Value, this.doc );
                    break;

                case XmlNodeType.EntityReference:{
                    XmlEntityReference eref = new XmlEntityReference( reader.Name, this.doc );
                    if ( reader.CanResolveEntity ) {
                        reader.ResolveEntity();
                        LoadEntityChildren( eref );
                        //what if eref doesn't have children at all? should we just put a Empty String text here?
                        if ( eref.ChildNodes.Count == 0 )
                            eref.AppendChild( new XmlText("") );
                    }
                    node = eref;
                    break;
                }

                case XmlNodeType.ProcessingInstruction:
                    node = new XmlProcessingInstruction( reader.Name, reader.Value, this.doc );
                    break;

                case XmlNodeType.Comment:
                    node = new XmlComment( reader.Value, this.doc );
                    break;

                default:
                    throw new InvalidOperationException(string.Format(Res.GetString(Res.Xdom_Load_NodeType),reader.NodeType.ToString()));
            }

            return node;
        }
Beispiel #12
0
		internal DOMEntityReference(XmlEntityReference/*!*/ xmlEntityReference)
			: base(ScriptContext.CurrentContext, true)
		{
			this.XmlEntityReference = xmlEntityReference;
		}
Beispiel #13
0
        private XmlNode LoadEntityChildren()
        {
            XmlNode node = null;

            // We do not use creator functions on XmlDocument, b/c we do not want to let users extend the nodes that are children of entity nodes (also, if we do
            // this, XmlDataDocument will have a problem, b/c they do not know that those nodes should not be mapped).
            switch (reader.NodeType)
            {
            case XmlNodeType.EndElement:
            case XmlNodeType.EndEntity:
                break;

            case XmlNodeType.Element: {
                bool fEmptyElement = reader.IsEmptyElement;

                XmlElement element = new XmlElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                element.IsEmpty = fEmptyElement;

                while (reader.MoveToNextAttribute())
                {
                    XmlAttribute attr = (XmlAttribute)LoadEntityChildren();
                    element.Attributes.Append(attr);
                }

                // recursively load all children.
                if (!fEmptyElement)
                {
                    LoadEntityChildren(element);
                }

                node = element;
                break;
            }

            case XmlNodeType.Attribute:
                if (reader.IsDefault)
                {
                    XmlUnspecifiedAttribute attr = new XmlUnspecifiedAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                    LoadEntityAttributeChildren(attr);
                    attr.SetSpecified(false);
                    node = attr;
                }
                else
                {
                    XmlAttribute attr = new XmlAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, this.doc);
                    LoadEntityAttributeChildren(attr);
                    node = attr;
                }
                break;

            case XmlNodeType.SignificantWhitespace:
                node = new XmlSignificantWhitespace(reader.Value, this.doc);
                break;

            case XmlNodeType.Whitespace:
                if (preserveWhitespace)
                {
                    node = new XmlWhitespace(reader.Value, this.doc);
                }
                else
                {
                    // if preserveWhitespace is false skip all subsequent WS nodes and position on the first non-WS node
                    do
                    {
                        if (!reader.Read())
                        {
                            return(null);
                        }
                    } while (reader.NodeType == XmlNodeType.Whitespace);
                    node = LoadEntityChildren();       // Skip WS node if preserveWhitespace is false
                }
                break;

            case XmlNodeType.Text:
                node = new XmlText(reader.Value, this.doc);
                break;

            case XmlNodeType.CDATA:
                node = new XmlCDataSection(reader.Value, this.doc);
                break;

            case XmlNodeType.EntityReference: {
                XmlEntityReference eref = new XmlEntityReference(reader.Name, this.doc);
                if (reader.CanResolveEntity)
                {
                    reader.ResolveEntity();
                    LoadEntityChildren(eref);
                    //what if eref doesn't have children at all? should we just put a Empty String text here?
                    if (eref.ChildNodes.Count == 0)
                    {
                        eref.AppendChild(new XmlText(""));
                    }
                }
                node = eref;
                break;
            }

            case XmlNodeType.ProcessingInstruction:
                node = new XmlProcessingInstruction(reader.Name, reader.Value, this.doc);
                break;

            case XmlNodeType.Comment:
                node = new XmlComment(reader.Value, this.doc);
                break;

            default:
                throw new InvalidOperationException(string.Format(Res.GetString(Res.Xdom_Load_NodeType), reader.NodeType.ToString()));
            }

            return(node);
        }
Beispiel #14
0
        // Used by the ReadNode method for recursively building a DOM subtree.
        internal XmlNode ReadNodeInternal(XmlReader r)
        {
            switch (r.NodeType)
            {
            case XmlNodeType.Attribute:
            {
                // create the attribute
                XmlAttribute att = CreateAttribute
                                       (r.Prefix, r.LocalName, r.NamespaceURI);

                // read and append the children
                ReadChildren(r, att);

                // return the attribute
                return(att);
            }
            // Not reached.

            case XmlNodeType.CDATA:
            {
                // create the character data section
                XmlCDataSection cdata = CreateCDataSection(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the character data section
                return(cdata);
            }
            // Not reached.

            case XmlNodeType.Comment:
            {
                // create the comment
                XmlComment comment = CreateComment(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the comment
                return(comment);
            }
            // Not reached.

            case XmlNodeType.DocumentType:
            {
                // create the document type
                XmlDocumentType doctype = CreateDocumentType
                                              (r.Name, r["PUBLIC"], r["SYSTEM"], r.Value);

                // advance the reader to the next node
                r.Read();

                // return the document type
                return(doctype);
            }
            // Not reached.

            case XmlNodeType.Element:
            {
                // create the element
                XmlElement elem = CreateElement
                                      (r.Prefix, r.LocalName, r.NamespaceURI);
                bool isEmptyElement = r.IsEmptyElement;

                // read the attributes
                while (r.MoveToNextAttribute())
                {
                    XmlAttribute att = (XmlAttribute)ReadNodeInternal(r);
                    elem.SetAttributeNode(att);
                }
                r.MoveToElement();

                // return now if there are no children
                if (isEmptyElement)
                {
                    // advance the reader to the next node
                    r.Read();

                    // return the empty element
                    return(elem);
                }

                elem.IsEmpty = isEmptyElement;

                // read and append the children
                ReadChildren(r, elem);

                // return the element
                return(elem);
            }
            // Not reached.

            case XmlNodeType.DocumentFragment:
            case XmlNodeType.EndElement:
            case XmlNodeType.EndEntity:
            case XmlNodeType.Entity:
            case XmlNodeType.Notation:
            {
                // TODO

                // advance the reader to the next node
                r.Read();

                // nothing to return
                return(null);
            }
            // Not reached.

            case XmlNodeType.EntityReference:
            {
                // create the entity reference
                XmlEntityReference er = CreateEntityReference(r.Name);

                // advance the reader to the next node
                r.Read();

                // return the entity reference
                return(er);
            }
            // Not reached.

            case XmlNodeType.ProcessingInstruction:
            {
                // create the processing instruction
                XmlProcessingInstruction pi = CreateProcessingInstruction
                                                  (r.Name, r.Value);

                // advance the reader to the next node
                r.Read();

                // return the processing instruction
                return(pi);
            }
            // Not reached.

            case XmlNodeType.SignificantWhitespace:
            {
                // create the significant whitespace
                XmlSignificantWhitespace sws = CreateSignificantWhitespace
                                                   (r.Value);

                // advance the reader to the next node
                r.Read();

                // return the significant whitespace
                return(sws);
            }
            // Not reached.

            case XmlNodeType.Text:
            {
                // create the text
                XmlText text = CreateTextNode(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the text
                return(text);
            }
            // Not reached.

            case XmlNodeType.Whitespace:
            {
                // if whitespace preservation is off, skip whitespace
                if (!preserveWhitespace)
                {
                    while (r.Read())
                    {
                        if (r.NodeType != XmlNodeType.Whitespace)
                        {
                            return(null);
                        }
                    }
                    return(null);
                }

                // create the whitespace
                XmlWhitespace ws = CreateWhitespace(r.Value);

                // advance the reader to the next node
                r.Read();

                // return the whitespace
                return(ws);
            }
            // Not reached.

            case XmlNodeType.XmlDeclaration:
            {
                // set up the defaults
                String e = String.Empty;
                String s = String.Empty;

                // read the version
                r.MoveToNextAttribute();

                // read the optional attributes
                if (r.MoveToNextAttribute())
                {
                    if (r.Name == "encoding")
                    {
                        e = r.Value;
                        if (r.MoveToNextAttribute())
                        {
                            s = r.Value;
                        }
                    }
                    else
                    {
                        s = r.Value;
                    }
                }

                // create the xml declaration
                XmlDeclaration xml = CreateXmlDeclaration("1.0", e, s);

                // advance the reader to the next node
                r.Read();

                // return the xml declaration
                return(xml);
            }
            // Not reached.

            default:
            {
                throw new InvalidOperationException(/* TODO */);
            }
                // Not reached.
            }
        }