Ejemplo n.º 1
0
        internal void ReadContentFrom(XmlReader r)
        {
            if (r.ReadState != ReadState.Interactive)
            {
                throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive);
            }
            XContainer     c      = this;
            NamespaceCache eCache = new NamespaceCache();
            NamespaceCache aCache = new NamespaceCache();

            do
            {
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                    XElement e = new XElement(eCache.Get(r.NamespaceURI).GetName(r.LocalName));
                    if (r.MoveToFirstAttribute())
                    {
                        do
                        {
                            e.AppendAttributeSkipNotify(new XAttribute(aCache.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value));
                        } while (r.MoveToNextAttribute());
                        r.MoveToElement();
                    }
                    c.AddNodeSkipNotify(e);
                    if (!r.IsEmptyElement)
                    {
                        c = e;
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (c.content == null)
                    {
                        c.content = string.Empty;
                    }
                    if (c == this)
                    {
                        return;
                    }
                    c = c.parent;
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.SignificantWhitespace:
                case XmlNodeType.Whitespace:
                    c.AddStringSkipNotify(r.Value);
                    break;

                case XmlNodeType.CDATA:
                    c.AddNodeSkipNotify(new XCData(r.Value));
                    break;

                case XmlNodeType.Comment:
                    c.AddNodeSkipNotify(new XComment(r.Value));
                    break;

                case XmlNodeType.ProcessingInstruction:
                    c.AddNodeSkipNotify(new XProcessingInstruction(r.Name, r.Value));
                    break;

                case XmlNodeType.DocumentType:
                    c.AddNodeSkipNotify(new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value));
                    break;

                case XmlNodeType.EntityReference:
                    if (!r.CanResolveEntity)
                    {
                        throw new InvalidOperationException(SR.InvalidOperation_UnresolvedEntityReference);
                    }
                    r.ResolveEntity();
                    break;

                case XmlNodeType.EndEntity:
                    break;

                default:
                    throw new InvalidOperationException(SR.Format(SR.InvalidOperation_UnexpectedNodeType, r.NodeType));
                }
            } while (r.Read());
        }
Ejemplo n.º 2
0
 internal void ReadContentFrom(XmlReader r, LoadOptions o)
 {
     if ((o & (LoadOptions.SetBaseUri | LoadOptions.SetLineInfo)) == 0)
     {
         ReadContentFrom(r);
         return;
     }
     if (r.ReadState != ReadState.Interactive) throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive);
     XContainer c = this;
     XNode n = null;
     NamespaceCache eCache = new NamespaceCache();
     NamespaceCache aCache = new NamespaceCache();
     string baseUri = (o & LoadOptions.SetBaseUri) != 0 ? r.BaseURI : null;
     IXmlLineInfo li = (o & LoadOptions.SetLineInfo) != 0 ? r as IXmlLineInfo : null;
     do
     {
         string uri = r.BaseURI;
         switch (r.NodeType)
         {
             case XmlNodeType.Element:
                 {
                     XElement e = new XElement(eCache.Get(r.NamespaceURI).GetName(r.LocalName));
                     if (baseUri != null && baseUri != uri)
                     {
                         e.SetBaseUri(uri);
                     }
                     if (li != null && li.HasLineInfo())
                     {
                         e.SetLineInfo(li.LineNumber, li.LinePosition);
                     }
                     if (r.MoveToFirstAttribute())
                     {
                         do
                         {
                             XAttribute a = new XAttribute(aCache.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
                             if (li != null && li.HasLineInfo())
                             {
                                 a.SetLineInfo(li.LineNumber, li.LinePosition);
                             }
                             e.AppendAttributeSkipNotify(a);
                         } while (r.MoveToNextAttribute());
                         r.MoveToElement();
                     }
                     c.AddNodeSkipNotify(e);
                     if (!r.IsEmptyElement)
                     {
                         c = e;
                         if (baseUri != null)
                         {
                             baseUri = uri;
                         }
                     }
                     break;
                 }
             case XmlNodeType.EndElement:
                 {
                     if (c.content == null)
                     {
                         c.content = string.Empty;
                     }
                     // Store the line info of the end element tag.
                     // Note that since we've got EndElement the current container must be an XElement
                     XElement e = c as XElement;
                     Debug.Assert(e != null, "EndElement received but the current container is not an element.");
                     if (e != null && li != null && li.HasLineInfo())
                     {
                         e.SetEndElementLineInfo(li.LineNumber, li.LinePosition);
                     }
                     if (c == this) return;
                     if (baseUri != null && c.HasBaseUri)
                     {
                         baseUri = c.parent.BaseUri;
                     }
                     c = c.parent;
                     break;
                 }
             case XmlNodeType.Text:
             case XmlNodeType.SignificantWhitespace:
             case XmlNodeType.Whitespace:
                 if ((baseUri != null && baseUri != uri) ||
                     (li != null && li.HasLineInfo()))
                 {
                     n = new XText(r.Value);
                 }
                 else
                 {
                     c.AddStringSkipNotify(r.Value);
                 }
                 break;
             case XmlNodeType.CDATA:
                 n = new XCData(r.Value);
                 break;
             case XmlNodeType.Comment:
                 n = new XComment(r.Value);
                 break;
             case XmlNodeType.ProcessingInstruction:
                 n = new XProcessingInstruction(r.Name, r.Value);
                 break;
             case XmlNodeType.DocumentType:
                 n = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value);
                 break;
             case XmlNodeType.EntityReference:
                 if (!r.CanResolveEntity) throw new InvalidOperationException(SR.InvalidOperation_UnresolvedEntityReference);
                 r.ResolveEntity();
                 break;
             case XmlNodeType.EndEntity:
                 break;
             default:
                 throw new InvalidOperationException(SR.Format(SR.InvalidOperation_UnexpectedNodeType, r.NodeType));
         }
         if (n != null)
         {
             if (baseUri != null && baseUri != uri)
             {
                 n.SetBaseUri(uri);
             }
             if (li != null && li.HasLineInfo())
             {
                 n.SetLineInfo(li.LineNumber, li.LinePosition);
             }
             c.AddNodeSkipNotify(n);
             n = null;
         }
     } while (r.Read());
 }
Ejemplo n.º 3
0
        internal void ReadContentFrom(XmlReader r, LoadOptions o)
        {
            if ((o & (LoadOptions.SetBaseUri | LoadOptions.SetLineInfo)) == 0)
            {
                ReadContentFrom(r);
                return;
            }
            if (r.ReadState != ReadState.Interactive)
            {
                throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive);
            }
            XContainer     c       = this;
            XNode          n       = null;
            NamespaceCache eCache  = new NamespaceCache();
            NamespaceCache aCache  = new NamespaceCache();
            string         baseUri = (o & LoadOptions.SetBaseUri) != 0 ? r.BaseURI : null;
            IXmlLineInfo   li      = (o & LoadOptions.SetLineInfo) != 0 ? r as IXmlLineInfo : null;

            do
            {
                string uri = r.BaseURI;
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                {
                    XElement e = new XElement(eCache.Get(r.NamespaceURI).GetName(r.LocalName));
                    if (baseUri != null && baseUri != uri)
                    {
                        e.SetBaseUri(uri);
                    }
                    if (li != null && li.HasLineInfo())
                    {
                        e.SetLineInfo(li.LineNumber, li.LinePosition);
                    }
                    if (r.MoveToFirstAttribute())
                    {
                        do
                        {
                            XAttribute a = new XAttribute(aCache.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
                            if (li != null && li.HasLineInfo())
                            {
                                a.SetLineInfo(li.LineNumber, li.LinePosition);
                            }
                            e.AppendAttributeSkipNotify(a);
                        } while (r.MoveToNextAttribute());
                        r.MoveToElement();
                    }
                    c.AddNodeSkipNotify(e);
                    if (!r.IsEmptyElement)
                    {
                        c = e;
                        if (baseUri != null)
                        {
                            baseUri = uri;
                        }
                    }
                    break;
                }

                case XmlNodeType.EndElement:
                {
                    if (c.content == null)
                    {
                        c.content = string.Empty;
                    }
                    // Store the line info of the end element tag.
                    // Note that since we've got EndElement the current container must be an XElement
                    XElement e = c as XElement;
                    Debug.Assert(e != null, "EndElement received but the current container is not an element.");
                    if (e != null && li != null && li.HasLineInfo())
                    {
                        e.SetEndElementLineInfo(li.LineNumber, li.LinePosition);
                    }
                    if (c == this)
                    {
                        return;
                    }
                    if (baseUri != null && c.HasBaseUri)
                    {
                        baseUri = c.parent.BaseUri;
                    }
                    c = c.parent;
                    break;
                }

                case XmlNodeType.Text:
                case XmlNodeType.SignificantWhitespace:
                case XmlNodeType.Whitespace:
                    if ((baseUri != null && baseUri != uri) ||
                        (li != null && li.HasLineInfo()))
                    {
                        n = new XText(r.Value);
                    }
                    else
                    {
                        c.AddStringSkipNotify(r.Value);
                    }
                    break;

                case XmlNodeType.CDATA:
                    n = new XCData(r.Value);
                    break;

                case XmlNodeType.Comment:
                    n = new XComment(r.Value);
                    break;

                case XmlNodeType.ProcessingInstruction:
                    n = new XProcessingInstruction(r.Name, r.Value);
                    break;

                case XmlNodeType.DocumentType:
                    n = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value);
                    break;

                case XmlNodeType.EntityReference:
                    if (!r.CanResolveEntity)
                    {
                        throw new InvalidOperationException(SR.InvalidOperation_UnresolvedEntityReference);
                    }
                    r.ResolveEntity();
                    break;

                case XmlNodeType.EndEntity:
                    break;

                default:
                    throw new InvalidOperationException(SR.Format(SR.InvalidOperation_UnexpectedNodeType, r.NodeType));
                }
                if (n != null)
                {
                    if (baseUri != null && baseUri != uri)
                    {
                        n.SetBaseUri(uri);
                    }
                    if (li != null && li.HasLineInfo())
                    {
                        n.SetLineInfo(li.LineNumber, li.LinePosition);
                    }
                    c.AddNodeSkipNotify(n);
                    n = null;
                }
            } while (r.Read());
        }
Ejemplo n.º 4
0
 internal void ReadContentFrom(XmlReader r)
 {
     if (r.ReadState != ReadState.Interactive) throw new InvalidOperationException(SR.InvalidOperation_ExpectedInteractive);
     XContainer c = this;
     NamespaceCache eCache = new NamespaceCache();
     NamespaceCache aCache = new NamespaceCache();
     do
     {
         switch (r.NodeType)
         {
             case XmlNodeType.Element:
                 XElement e = new XElement(eCache.Get(r.NamespaceURI).GetName(r.LocalName));
                 if (r.MoveToFirstAttribute())
                 {
                     do
                     {
                         e.AppendAttributeSkipNotify(new XAttribute(aCache.Get(r.Prefix.Length == 0 ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value));
                     } while (r.MoveToNextAttribute());
                     r.MoveToElement();
                 }
                 c.AddNodeSkipNotify(e);
                 if (!r.IsEmptyElement)
                 {
                     c = e;
                 }
                 break;
             case XmlNodeType.EndElement:
                 if (c.content == null)
                 {
                     c.content = string.Empty;
                 }
                 if (c == this) return;
                 c = c.parent;
                 break;
             case XmlNodeType.Text:
             case XmlNodeType.SignificantWhitespace:
             case XmlNodeType.Whitespace:
                 c.AddStringSkipNotify(r.Value);
                 break;
             case XmlNodeType.CDATA:
                 c.AddNodeSkipNotify(new XCData(r.Value));
                 break;
             case XmlNodeType.Comment:
                 c.AddNodeSkipNotify(new XComment(r.Value));
                 break;
             case XmlNodeType.ProcessingInstruction:
                 c.AddNodeSkipNotify(new XProcessingInstruction(r.Name, r.Value));
                 break;
             case XmlNodeType.DocumentType:
                 c.AddNodeSkipNotify(new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value));
                 break;
             case XmlNodeType.EntityReference:
                 if (!r.CanResolveEntity) throw new InvalidOperationException(SR.InvalidOperation_UnresolvedEntityReference);
                 r.ResolveEntity();
                 break;
             case XmlNodeType.EndEntity:
                 break;
             default:
                 throw new InvalidOperationException(SR.Format(SR.InvalidOperation_UnexpectedNodeType, r.NodeType));
         }
     } while (r.Read());
 }
Ejemplo n.º 5
0
        internal void ReadContentFrom(XmlReader r, LoadOptions o)
        {
            if ((o & (LoadOptions.SetLineInfo | LoadOptions.SetBaseUri)) == LoadOptions.None)
            {
                this.ReadContentFrom(r);
            }
            else
            {
                if (r.ReadState != System.Xml.ReadState.Interactive)
                {
                    throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_ExpectedInteractive"));
                }
                XContainer     parent  = this;
                XNode          n       = null;
                NamespaceCache cache   = new NamespaceCache();
                NamespaceCache cache2  = new NamespaceCache();
                string         baseUri = ((o & LoadOptions.SetBaseUri) != LoadOptions.None) ? r.BaseURI : null;
                IXmlLineInfo   info    = ((o & LoadOptions.SetLineInfo) != LoadOptions.None) ? (r as IXmlLineInfo) : null;
                do
                {
                    string baseURI = r.BaseURI;
                    switch (r.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        XElement element = new XElement(cache.Get(r.NamespaceURI).GetName(r.LocalName));
                        if ((baseUri != null) && (baseUri != baseURI))
                        {
                            element.SetBaseUri(baseURI);
                        }
                        if ((info != null) && info.HasLineInfo())
                        {
                            element.SetLineInfo(info.LineNumber, info.LinePosition);
                        }
                        if (r.MoveToFirstAttribute())
                        {
                            do
                            {
                                XAttribute a = new XAttribute(cache2.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
                                if ((info != null) && info.HasLineInfo())
                                {
                                    a.SetLineInfo(info.LineNumber, info.LinePosition);
                                }
                                element.AppendAttributeSkipNotify(a);
                            }while (r.MoveToNextAttribute());
                            r.MoveToElement();
                        }
                        parent.AddNodeSkipNotify(element);
                        if (!r.IsEmptyElement)
                        {
                            parent = element;
                            if (baseUri != null)
                            {
                                baseUri = baseURI;
                            }
                        }
                        break;
                    }

                    case XmlNodeType.Text:
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        if (((baseUri == null) || (baseUri == baseURI)) && ((info == null) || !info.HasLineInfo()))
                        {
                            parent.AddStringSkipNotify(r.Value);
                        }
                        else
                        {
                            n = new XText(r.Value);
                        }
                        break;

                    case XmlNodeType.CDATA:
                        n = new XCData(r.Value);
                        break;

                    case XmlNodeType.EntityReference:
                        if (!r.CanResolveEntity)
                        {
                            throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnresolvedEntityReference"));
                        }
                        r.ResolveEntity();
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        n = new XProcessingInstruction(r.Name, r.Value);
                        break;

                    case XmlNodeType.Comment:
                        n = new XComment(r.Value);
                        break;

                    case XmlNodeType.DocumentType:
                        n = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value, r.DtdInfo);
                        break;

                    case XmlNodeType.EndElement:
                    {
                        if (parent.content == null)
                        {
                            parent.content = string.Empty;
                        }
                        XElement element2 = parent as XElement;
                        if (((element2 != null) && (info != null)) && info.HasLineInfo())
                        {
                            element2.SetEndElementLineInfo(info.LineNumber, info.LinePosition);
                        }
                        if (parent == this)
                        {
                            return;
                        }
                        if ((baseUri != null) && parent.HasBaseUri)
                        {
                            baseUri = parent.parent.BaseUri;
                        }
                        parent = parent.parent;
                        break;
                    }

                    case XmlNodeType.EndEntity:
                        break;

                    default:
                        throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnexpectedNodeType", new object[] { r.NodeType }));
                    }
                    if (n != null)
                    {
                        if ((baseUri != null) && (baseUri != baseURI))
                        {
                            n.SetBaseUri(baseURI);
                        }
                        if ((info != null) && info.HasLineInfo())
                        {
                            n.SetLineInfo(info.LineNumber, info.LinePosition);
                        }
                        parent.AddNodeSkipNotify(n);
                        n = null;
                    }
                }while (r.Read());
            }
        }
Ejemplo n.º 6
0
        internal void ReadContentFrom(XmlReader r)
        {
            if (r.ReadState != System.Xml.ReadState.Interactive)
            {
                throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_ExpectedInteractive"));
            }
            XContainer     parent = this;
            NamespaceCache cache  = new NamespaceCache();
            NamespaceCache cache2 = new NamespaceCache();

            do
            {
                switch (r.NodeType)
                {
                case XmlNodeType.Element:
                {
                    XElement n = new XElement(cache.Get(r.NamespaceURI).GetName(r.LocalName));
                    if (r.MoveToFirstAttribute())
                    {
                        do
                        {
                            n.AppendAttributeSkipNotify(new XAttribute(cache2.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value));
                        }while (r.MoveToNextAttribute());
                        r.MoveToElement();
                    }
                    parent.AddNodeSkipNotify(n);
                    if (!r.IsEmptyElement)
                    {
                        parent = n;
                    }
                    break;
                }

                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    parent.AddStringSkipNotify(r.Value);
                    break;

                case XmlNodeType.CDATA:
                    parent.AddNodeSkipNotify(new XCData(r.Value));
                    break;

                case XmlNodeType.EntityReference:
                    if (!r.CanResolveEntity)
                    {
                        throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnresolvedEntityReference"));
                    }
                    r.ResolveEntity();
                    break;

                case XmlNodeType.ProcessingInstruction:
                    parent.AddNodeSkipNotify(new XProcessingInstruction(r.Name, r.Value));
                    break;

                case XmlNodeType.Comment:
                    parent.AddNodeSkipNotify(new XComment(r.Value));
                    break;

                case XmlNodeType.DocumentType:
                    parent.AddNodeSkipNotify(new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value, r.DtdInfo));
                    break;

                case XmlNodeType.EndElement:
                    if (parent.content == null)
                    {
                        parent.content = string.Empty;
                    }
                    if (parent == this)
                    {
                        return;
                    }
                    parent = parent.parent;
                    break;

                case XmlNodeType.EndEntity:
                    break;

                default:
                    throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnexpectedNodeType", new object[] { r.NodeType }));
                }
            }while (r.Read());
        }
        internal void ReadContentFrom(XmlReader r, LoadOptions o)
        {
            if ((o & (LoadOptions.SetLineInfo | LoadOptions.SetBaseUri)) == LoadOptions.None)
            {
                this.ReadContentFrom(r);
            }
            else
            {
                if (r.ReadState != System.Xml.ReadState.Interactive)
                {
                    throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_ExpectedInteractive"));
                }
                XContainer parent = this;
                XNode n = null;
                NamespaceCache cache = new NamespaceCache();
                NamespaceCache cache2 = new NamespaceCache();
                string baseUri = ((o & LoadOptions.SetBaseUri) != LoadOptions.None) ? r.BaseURI : null;
                IXmlLineInfo info = ((o & LoadOptions.SetLineInfo) != LoadOptions.None) ? (r as IXmlLineInfo) : null;
                do
                {
                    string baseURI = r.BaseURI;
                    switch (r.NodeType)
                    {
                        case XmlNodeType.Element:
                        {
                            XElement element = new XElement(cache.Get(r.NamespaceURI).GetName(r.LocalName));
                            if ((baseUri != null) && (baseUri != baseURI))
                            {
                                element.SetBaseUri(baseURI);
                            }
                            if ((info != null) && info.HasLineInfo())
                            {
                                element.SetLineInfo(info.LineNumber, info.LinePosition);
                            }
                            if (r.MoveToFirstAttribute())
                            {
                                do
                                {
                                    XAttribute a = new XAttribute(cache2.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value);
                                    if ((info != null) && info.HasLineInfo())
                                    {
                                        a.SetLineInfo(info.LineNumber, info.LinePosition);
                                    }
                                    element.AppendAttributeSkipNotify(a);
                                }
                                while (r.MoveToNextAttribute());
                                r.MoveToElement();
                            }
                            parent.AddNodeSkipNotify(element);
                            if (!r.IsEmptyElement)
                            {
                                parent = element;
                                if (baseUri != null)
                                {
                                    baseUri = baseURI;
                                }
                            }
                            break;
                        }
                        case XmlNodeType.Text:
                        case XmlNodeType.Whitespace:
                        case XmlNodeType.SignificantWhitespace:
                            if (((baseUri == null) || (baseUri == baseURI)) && ((info == null) || !info.HasLineInfo()))
                            {
                                parent.AddStringSkipNotify(r.Value);
                            }
                            else
                            {
                                n = new XText(r.Value);
                            }
                            break;

                        case XmlNodeType.CDATA:
                            n = new XCData(r.Value);
                            break;

                        case XmlNodeType.EntityReference:
                            if (!r.CanResolveEntity)
                            {
                                throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnresolvedEntityReference"));
                            }
                            r.ResolveEntity();
                            break;

                        case XmlNodeType.ProcessingInstruction:
                            n = new XProcessingInstruction(r.Name, r.Value);
                            break;

                        case XmlNodeType.Comment:
                            n = new XComment(r.Value);
                            break;

                        case XmlNodeType.DocumentType:
                            n = new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value, r.DtdInfo);
                            break;

                        case XmlNodeType.EndElement:
                        {
                            if (parent.content == null)
                            {
                                parent.content = string.Empty;
                            }
                            XElement element2 = parent as XElement;
                            if (((element2 != null) && (info != null)) && info.HasLineInfo())
                            {
                                element2.SetEndElementLineInfo(info.LineNumber, info.LinePosition);
                            }
                            if (parent == this)
                            {
                                return;
                            }
                            if ((baseUri != null) && parent.HasBaseUri)
                            {
                                baseUri = parent.parent.BaseUri;
                            }
                            parent = parent.parent;
                            break;
                        }
                        case XmlNodeType.EndEntity:
                            break;

                        default:
                            throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnexpectedNodeType", new object[] { r.NodeType }));
                    }
                    if (n != null)
                    {
                        if ((baseUri != null) && (baseUri != baseURI))
                        {
                            n.SetBaseUri(baseURI);
                        }
                        if ((info != null) && info.HasLineInfo())
                        {
                            n.SetLineInfo(info.LineNumber, info.LinePosition);
                        }
                        parent.AddNodeSkipNotify(n);
                        n = null;
                    }
                }
                while (r.Read());
            }
        }
        internal void ReadContentFrom(XmlReader r)
        {
            if (r.ReadState != System.Xml.ReadState.Interactive)
            {
                throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_ExpectedInteractive"));
            }
            XContainer parent = this;
            NamespaceCache cache = new NamespaceCache();
            NamespaceCache cache2 = new NamespaceCache();
            do
            {
                switch (r.NodeType)
                {
                    case XmlNodeType.Element:
                    {
                        XElement n = new XElement(cache.Get(r.NamespaceURI).GetName(r.LocalName));
                        if (r.MoveToFirstAttribute())
                        {
                            do
                            {
                                n.AppendAttributeSkipNotify(new XAttribute(cache2.Get((r.Prefix.Length == 0) ? string.Empty : r.NamespaceURI).GetName(r.LocalName), r.Value));
                            }
                            while (r.MoveToNextAttribute());
                            r.MoveToElement();
                        }
                        parent.AddNodeSkipNotify(n);
                        if (!r.IsEmptyElement)
                        {
                            parent = n;
                        }
                        break;
                    }
                    case XmlNodeType.Text:
                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        parent.AddStringSkipNotify(r.Value);
                        break;

                    case XmlNodeType.CDATA:
                        parent.AddNodeSkipNotify(new XCData(r.Value));
                        break;

                    case XmlNodeType.EntityReference:
                        if (!r.CanResolveEntity)
                        {
                            throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnresolvedEntityReference"));
                        }
                        r.ResolveEntity();
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        parent.AddNodeSkipNotify(new XProcessingInstruction(r.Name, r.Value));
                        break;

                    case XmlNodeType.Comment:
                        parent.AddNodeSkipNotify(new XComment(r.Value));
                        break;

                    case XmlNodeType.DocumentType:
                        parent.AddNodeSkipNotify(new XDocumentType(r.LocalName, r.GetAttribute("PUBLIC"), r.GetAttribute("SYSTEM"), r.Value, r.DtdInfo));
                        break;

                    case XmlNodeType.EndElement:
                        if (parent.content == null)
                        {
                            parent.content = string.Empty;
                        }
                        if (parent == this)
                        {
                            return;
                        }
                        parent = parent.parent;
                        break;

                    case XmlNodeType.EndEntity:
                        break;

                    default:
                        throw new InvalidOperationException(System.Xml.Linq.Res.GetString("InvalidOperation_UnexpectedNodeType", new object[] { r.NodeType }));
                }
            }
            while (r.Read());
        }