private void ReadDocument(XmlReader reader) { ServiceDocument result = CreateDocumentInstance(); try { SyndicationFeedFormatter.MoveToStartElement(reader); bool elementIsEmpty = reader.IsEmptyElement; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.LocalName == "lang" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.Language = reader.Value; } else if (reader.LocalName == "base" && reader.NamespaceURI == Atom10FeedFormatter.XmlNs) { result.BaseUri = 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(); if (!elementIsEmpty) { try { while (reader.IsStartElement()) { if (reader.IsStartElement(App10Constants.Workspace, App10Constants.Namespace)) { result.Workspaces.Add(ReadWorkspace(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(); } catch (FormatException e) { throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e); } catch (ArgumentException e) { throw new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDocument), e); } SetDocument(result); }
public AtomPub10ServiceDocumentFormatter(ServiceDocument documentToWrite) : base(documentToWrite) { _maxExtensionSize = int.MaxValue; _documentType = documentToWrite.GetType(); }
protected ServiceDocumentFormatter(ServiceDocument documentToWrite !!) {
private async Task <Workspace> ReadWorkspaceAsync(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, await reader.GetValueAsync()); } else { string ns = reader.NamespaceURI; string name = reader.LocalName; if (FeedUtils.IsXmlns(name, ns) || FeedUtils.IsXmlSchemaType(name, ns)) { continue; } string val = await reader.GetValueAsync(); if (!TryParseAttribute(name, ns, val, result, Version)) { if (_preserveAttributeExtensions) { result.AttributeExtensions.Add(new XmlQualifiedName(reader.LocalName, reader.NamespaceURI), val); } } } } } XmlBuffer buffer = null; XmlDictionaryWriter extWriter = null; await reader.ReadStartElementAsync(); try { while (await reader.IsStartElementAsync()) { if (await reader.IsStartElementAsync(Atom10Constants.TitleTag, Atom10Constants.Atom10Namespace)) { result.Title = await new Atom10FeedFormatter().ReadTextContentFromAsync(reader, "//app:service/app:workspace/atom:title[@type]", _preserveAttributeExtensions); } else if (await reader.IsStartElementAsync(App10Constants.Collection, App10Constants.Namespace)) { result.Collections.Add(await ReadCollectionAsync(reader, result)); } else if (!TryParseElement(reader, result, Version)) { if (_preserveElementExtensions) { var tuple = await SyndicationFeedFormatter.CreateBufferIfRequiredAndWriteNodeAsync(buffer, extWriter, reader, _maxExtensionSize); buffer = tuple.Item1; extWriter = tuple.Item2; } else { await reader.SkipAsync(); } } } LoadElementExtensions(buffer, extWriter, result); } finally { if (extWriter != null) { extWriter.Close(); } } await reader.ReadEndElementAsync(); return(result); }
public AtomPub10ServiceDocumentFormatter(ServiceDocument documentToWrite) { Contract.Requires(documentToWrite != null); }
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); }