private void ReadPropertyValueIntoResult(AtomContentProperty property) { Debug.Assert(this.reader != null, "reader != null"); Debug.Assert(property != null, "property != null"); switch (this.reader.NodeType) { case XmlNodeType.CDATA: case XmlNodeType.SignificantWhitespace: case XmlNodeType.Text: if (!string.IsNullOrEmpty(property.Text)) { throw Error.InvalidOperation(Strings.Deserialize_MixedTextWithComment); } property.Text = this.reader.Value; break; case XmlNodeType.Comment: case XmlNodeType.Whitespace: case XmlNodeType.ProcessingInstruction: case XmlNodeType.EndElement: break; case XmlNodeType.Element: if (!string.IsNullOrEmpty(property.Text)) { throw Error.InvalidOperation(Strings.Deserialize_ExpectingSimpleValue); } property.EnsureProperties(); AtomContentProperty prop = this.ReadPropertyValue(); if (prop != null) { property.Properties.Add(prop); } break; default: throw Error.InvalidOperation(Strings.Deserialize_ExpectingSimpleValue); } }
private AtomContentProperty ReadPropertyValue() { Debug.Assert(this.reader != null, "reader != null"); Debug.Assert( this.reader.NodeType == XmlNodeType.Element, "reader.NodeType == XmlNodeType.Element -- otherwise caller is confused as to where the reader is"); if (!this.IsDataWebElement) { SkipToEndAtDepth(this.reader, this.reader.Depth); return null; } AtomContentProperty result = new AtomContentProperty(); result.Name = this.reader.LocalName; result.TypeName = this.reader.GetAttributeEx(XmlConstants.AtomTypeAttributeName, XmlConstants.DataWebMetadataNamespace); result.IsNull = Util.DoesNullAttributeSayTrue(this.reader); result.Text = result.IsNull ? null : string.Empty; if (!this.reader.IsEmptyElement) { int depth = this.reader.Depth; while (this.reader.Read()) { this.ReadPropertyValueIntoResult(result); if (this.reader.Depth == depth) { break; } } } return result; }
private void ParseCurrentLink(AtomEntry targetEntry) { Debug.Assert(targetEntry != null, "targetEntry != null"); Debug.Assert( this.reader.NodeType == XmlNodeType.Element, "this.reader.NodeType == XmlNodeType.Element -- otherwise we shouldn't try to parse a link"); Debug.Assert( this.reader.LocalName == "link", "this.reader.LocalName == 'link' -- otherwise we shouldn't try to parse a link"); string relation = this.reader.GetAttribute(XmlConstants.AtomLinkRelationAttributeName); if (relation == null) { return; } if (relation == XmlConstants.AtomEditRelationAttributeValue && targetEntry.EditLink == null) { string href = this.reader.GetAttribute(XmlConstants.AtomHRefAttributeName); if (string.IsNullOrEmpty(href)) { throw Error.InvalidOperation(Strings.Context_MissingEditLinkInResponseBody); } targetEntry.EditLink = this.ConvertHRefAttributeValueIntoURI(href); } else if (relation == XmlConstants.AtomSelfRelationAttributeValue && targetEntry.QueryLink == null) { string href = this.reader.GetAttribute(XmlConstants.AtomHRefAttributeName); if (string.IsNullOrEmpty(href)) { throw Error.InvalidOperation(Strings.Context_MissingSelfLinkInResponseBody); } targetEntry.QueryLink = this.ConvertHRefAttributeValueIntoURI(href); } else if (relation == XmlConstants.AtomEditMediaRelationAttributeValue && targetEntry.MediaEditUri == null) { string href = this.reader.GetAttribute(XmlConstants.AtomHRefAttributeName); if (string.IsNullOrEmpty(href)) { throw Error.InvalidOperation(Strings.Context_MissingEditMediaLinkInResponseBody); } targetEntry.MediaEditUri = this.ConvertHRefAttributeValueIntoURI(href); targetEntry.StreamETagText = this.reader.GetAttribute(XmlConstants.AtomETagAttributeName, XmlConstants.DataWebMetadataNamespace); } if (!this.reader.IsEmptyElement) { string propertyName = UriUtil.GetNameFromAtomLinkRelationAttribute(relation); if (propertyName == null) { return; } string propertyValueText = this.reader.GetAttribute(XmlConstants.AtomTypeAttributeName); bool isFeed; if (!IsAllowedLinkType(propertyValueText, out isFeed)) { return; } if (!ReadChildElement(this.reader, XmlConstants.AtomInlineElementName, XmlConstants.DataWebMetadataNamespace)) { return; } bool emptyInlineCollection = this.reader.IsEmptyElement; object propertyValue = null; if (!emptyInlineCollection) { AtomFeed nestedFeed = null; AtomEntry nestedEntry = null; List<AtomEntry> feedEntries = null; Debug.Assert(this.reader is Xml.XmlWrappingReader, "reader must be a instance of XmlWrappingReader"); string readerBaseUri = this.reader.BaseURI; XmlReader nestedReader = Xml.XmlWrappingReader.CreateReader(readerBaseUri, this.reader.ReadSubtree()); nestedReader.Read(); Debug.Assert(nestedReader.LocalName == "inline", "nestedReader.LocalName == 'inline'"); AtomParser nested = new AtomParser(nestedReader, this.entryCallback, this.typeScheme, this.currentDataNamespace); while (nested.Read()) { switch (nested.DataKind) { case AtomDataKind.Feed: feedEntries = new List<AtomEntry>(); nestedFeed = nested.CurrentFeed; propertyValue = nestedFeed; break; case AtomDataKind.Entry: nestedEntry = nested.CurrentEntry; if (feedEntries != null) { feedEntries.Add(nestedEntry); } else { propertyValue = nestedEntry; } break; case AtomDataKind.PagingLinks: break; default: throw new InvalidOperationException(Strings.AtomParser_UnexpectedContentUnderExpandedLink); } } if (nestedFeed != null) { Debug.Assert( nestedFeed.Entries == null, "nestedFeed.Entries == null -- otherwise someone initialized this for us"); nestedFeed.Entries = feedEntries; } } AtomContentProperty property = new AtomContentProperty(); property.Name = propertyName; if (emptyInlineCollection || propertyValue == null) { property.IsNull = true; if (isFeed) { property.Feed = new AtomFeed(); property.Feed.Entries = Enumerable.Empty<AtomEntry>(); } else { property.Entry = new AtomEntry(); property.Entry.IsNull = true; } } else { property.Feed = propertyValue as AtomFeed; property.Entry = propertyValue as AtomEntry; } targetEntry.DataValues.Add(property); } }