private Workspace ReadWorkspace(XmlReader reader, ServiceDocument document) { Workspace result = CreateWorkspace(document); result.BaseUri = document.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, result, Version)) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace)) { result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/atom:title[@type]", preserveAttributeExtensions: true); } else if (reader.IsStartElement(App10Constants.Collection, App10Constants.Namespace)) { result.Collections.Add(ReadCollection(reader, result)); } else if (!TryParseElement(reader, result, Version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, result); } finally { extWriter?.Close(); } reader.ReadEndElement(); return(result); }
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 ResourceCollectionInfo ReadCollection(XmlReader reader, Workspace workspace) { ResourceCollectionInfo result = CreateCollection(workspace); result.BaseUri = workspace.BaseUri; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = FeedUtils.CombineXmlBase(result.BaseUri, reader.Value); } else if (reader.LocalName == App10Constants.Href && reader.NamespaceURI == string.Empty) { result.Link = new Uri(reader.Value, UriKind.RelativeOrAbsolute); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = reader.Value; if (!TryParseAttribute(name, ns, val, result, Version)) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), reader.Value); } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; reader.ReadStartElement(); try { while (reader.IsStartElement()) { if (reader.IsStartElement(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace)) { result.Title = Atom10FeedFormatter.ReadTextContentFrom(reader, "//app:service/app:workspace/app:collection/atom:title[@type]", preserveAttributeExtensions: true); } else if (reader.IsStartElement(App10Constants.Categories, App10Constants.Namespace)) { result.Categories.Add(ReadCategories(reader, result.BaseUri, () => CreateInlineCategories(result), () => CreateReferencedCategories(result), Version, _maxExtensionSize)); } else if (reader.IsStartElement(App10Constants.Accept, App10Constants.Namespace)) { result.Accepts.Add(reader.ReadElementString()); } else if (!TryParseElement(reader, result, Version)) { SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNode(ref buffer, ref extWriter, reader, _maxExtensionSize); } } LoadElementExtensions(buffer, extWriter, result); } finally { extWriter?.Close(); } reader.ReadEndElement(); return(result); }
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); }