private ResourceCollectionInfo ReadCollection(XmlReader reader, Workspace workspace) { CreateInlineCategoriesDelegate inlineCategoriesFactory = null; CreateReferencedCategoriesDelegate referencedCategoriesFactory = null; ResourceCollectionInfo result = ServiceDocumentFormatter.CreateCollection(workspace); result.BaseUri = workspace.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value); } else { if ((reader.LocalName == "href") && (reader.NamespaceURI == string.Empty)) { result.Link = new Uri(reader.Value, UriKind.RelativeOrAbsolute); continue; } string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI)) { string str3 = reader.Value; if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, result, this.Version)) { if (this.preserveAttributeExtensions) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); try { while (reader.IsStartElement()) { if (reader.IsStartElement("title", "http://www.w3.org/2005/Atom")) { result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", this.preserveAttributeExtensions); } else { if (reader.IsStartElement("categories", "http://www.w3.org/2007/app")) { if (inlineCategoriesFactory == null) { inlineCategoriesFactory = () => ServiceDocumentFormatter.CreateInlineCategories(result); } if (referencedCategoriesFactory == null) { referencedCategoriesFactory = () => ServiceDocumentFormatter.CreateReferencedCategories(result); } result.Categories.Add(ReadCategories(reader, result.BaseUri, inlineCategoriesFactory, referencedCategoriesFactory, this.Version, this.preserveElementExtensions, this.preserveAttributeExtensions, this.maxExtensionSize)); continue; } if (reader.IsStartElement("accept", "http://www.w3.org/2007/app")) { result.Accepts.Add(reader.ReadElementString()); } else if (!ServiceDocumentFormatter.TryParseElement(reader, result, this.Version)) { if (this.preserveElementExtensions) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); reader.Skip(); } } } ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, result); } finally { if (extWriter != null) { extWriter.Close(); } } reader.ReadEndElement(); return(result); }
private static void ReadReferencedCategories(XmlReader reader, ReferencedCategoriesDocument referencedCategories, Uri baseUri, Uri link, string version, bool preserveElementExtensions, bool preserveAttributeExtensions, int maxExtensionSize) { referencedCategories.BaseUri = baseUri; referencedCategories.Link = link; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { referencedCategories.BaseUri = FeedUtils.CombineXmlBase(referencedCategories.BaseUri, reader.Value); } else { if ((reader.LocalName == "lang") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { referencedCategories.Language = reader.Value; continue; } if ((reader.LocalName != "href") || (reader.NamespaceURI != string.Empty)) { string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI)) { string str3 = reader.Value; if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, referencedCategories, version)) { if (preserveAttributeExtensions) { referencedCategories.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } } } reader.MoveToElement(); bool isEmptyElement = reader.IsEmptyElement; reader.ReadStartElement(); if (!isEmptyElement) { XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; try { while (reader.IsStartElement()) { if (!ServiceDocumentFormatter.TryParseElement(reader, referencedCategories, version)) { if (preserveElementExtensions) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, maxExtensionSize); } else { SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); reader.Skip(); } } } ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, referencedCategories); } finally { if (extWriter != null) { extWriter.Close(); } } reader.ReadEndElement(); } }
private Workspace ReadWorkspace(XmlReader reader, ServiceDocument document) { Workspace workspace = ServiceDocumentFormatter.CreateWorkspace(document); workspace.BaseUri = document.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { workspace.BaseUri = FeedUtils.CombineXmlBase(workspace.BaseUri, reader.Value); } else { string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI)) { string str3 = reader.Value; if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, workspace, this.Version)) { if (this.preserveAttributeExtensions) { workspace.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); try { while (reader.IsStartElement()) { if (reader.IsStartElement("title", "http://www.w3.org/2005/Atom")) { workspace.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/atom:title[@type]", this.preserveAttributeExtensions); } else { if (reader.IsStartElement("collection", "http://www.w3.org/2007/app")) { workspace.Collections.Add(this.ReadCollection(reader, workspace)); continue; } if (!ServiceDocumentFormatter.TryParseElement(reader, workspace, this.Version)) { if (this.preserveElementExtensions) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); reader.Skip(); } } } ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, workspace); } finally { if (extWriter != null) { extWriter.Close(); } } reader.ReadEndElement(); return(workspace); }
private void ReadDocument(XmlReader reader) { ServiceDocument document = this.CreateDocumentInstance(); try { SyndicationFeedFormatter.MoveToStartElement(reader); bool isEmptyElement = reader.IsEmptyElement; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.LocalName == "lang") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { document.Language = reader.Value; } else { if ((reader.LocalName == "base") && (reader.NamespaceURI == "http://www.w3.org/XML/1998/namespace")) { document.BaseUri = new Uri(reader.Value, UriKind.RelativeOrAbsolute); continue; } string namespaceURI = reader.NamespaceURI; string localName = reader.LocalName; if (!FeedUtils.IsXmlns(localName, namespaceURI) && !FeedUtils.IsXmlSchemaType(localName, namespaceURI)) { string str3 = reader.Value; if (!ServiceDocumentFormatter.TryParseAttribute(localName, namespaceURI, str3, document, this.Version)) { if (this.preserveAttributeExtensions) { document.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); } } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); if (!isEmptyElement) { try { while (reader.IsStartElement()) { if (reader.IsStartElement("workspace", "http://www.w3.org/2007/app")) { document.Workspaces.Add(this.ReadWorkspace(reader, document)); } else if (!ServiceDocumentFormatter.TryParseElement(reader, document, this.Version)) { if (this.preserveElementExtensions) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, this.maxExtensionSize); continue; } SyndicationFeedFormatter.TraceSyndicationElementIgnoredOnRead(reader); reader.Skip(); } } ServiceDocumentFormatter.LoadElementExtensions(buffer, extWriter, document); } finally { if (extWriter != null) { extWriter.Close(); } } } reader.ReadEndElement(); } catch (FormatException exception) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, "ErrorParsingDocument"), exception)); } catch (ArgumentException exception2) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(FeedUtils.AddLineInfo(reader, "ErrorParsingDocument"), exception2)); } this.SetDocument(document); }