本文整理汇总了C#中XmlReader.EnsureMarkup方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.EnsureMarkup方法的具体用法?C# XmlReader.EnsureMarkup怎么用?C# XmlReader.EnsureMarkup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlReader
的用法示例。
在下文中一共展示了XmlReader.EnsureMarkup方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParsePropertyValueAsync
static async Task<dynamic> ParsePropertyValueAsync(XmlReader reader, int level)
{
if (reader.IsEmptyElement)
{
await reader.ReadAsync();
return null;
}
string name = reader.Name;
dynamic value;
await reader.ReadAsync();
switch (reader.NodeType)
{
default:
value = await reader.ReadContentAsStringAsync();
break;
case XmlNodeType.Element:
// TODO: rewrite
switch (reader.Name)
{
case "s:dict":
value = await ParseDictionaryAsync(reader, level);
break;
case "s:list":
value = await ParseListAsync(reader, level);
break;
default: throw new InvalidDataException(); // TODO: Diagnostics : unexpected start tag
}
break;
case XmlNodeType.EndElement:
reader.EnsureMarkup(XmlNodeType.EndElement, name);
value = null;
break;
}
reader.EnsureMarkup(XmlNodeType.EndElement, name);
await reader.ReadAsync();
return value;
}
示例2: ParseListAsync
static async Task<ReadOnlyCollection<dynamic>> ParseListAsync(XmlReader reader, int level)
{
List<dynamic> value = new List<dynamic>();
if (!reader.IsEmptyElement)
{
await reader.ReadAsync();
while (reader.NodeType == XmlNodeType.Element && reader.Name == "s:item")
{
value.Add(await ParsePropertyValueAsync(reader, level + 1));
}
reader.EnsureMarkup(XmlNodeType.EndElement, "s:list");
}
await reader.ReadAsync();
return new ReadOnlyCollection<dynamic>(value);
}
示例3: ReadXmlAsync
/// <summary>
/// Asynchronously reads XML data into the current <see cref="AtomEntry"/>.
/// </summary>
/// <exception cref="InvalidDataException">
/// Thrown when an Invalid Data error condition occurs.
/// </exception>
/// <param name="reader">
/// The reader from which to read.
/// </param>
/// <returns>
/// A <see cref="Task"/> representing the operation.
/// </returns>
public async Task ReadXmlAsync(XmlReader reader)
{
Contract.Requires<ArgumentNullException>(reader != null, "reader");
this.Author = null;
this.Content = null;
this.Id = null;
this.Links = null;
this.Published = DateTime.MinValue;
this.Title = null;
this.Updated = DateTime.MinValue;
reader.Requires(await reader.MoveToDocumentElementAsync("entry"));
Dictionary<string, Uri> links = null;
await reader.ReadAsync();
while (reader.NodeType == XmlNodeType.Element)
{
string name = reader.Name;
switch (name)
{
case "title":
this.Title = await reader.ReadElementContentAsync(StringConverter.Instance);
break;
case "id":
this.Id = await reader.ReadElementContentAsync(UriConverter.Instance);
break;
case "author":
await reader.ReadAsync();
reader.EnsureMarkup(XmlNodeType.Element, "name");
this.Author = await reader.ReadElementContentAsync(StringConverter.Instance);
reader.EnsureMarkup(XmlNodeType.EndElement, "author");
await reader.ReadAsync();
break;
case "published":
this.Published = await reader.ReadElementContentAsync(DateTimeConverter.Instance);
break;
case "updated":
this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance);
break;
case "link":
if (links == null)
{
links = new Dictionary<string, Uri>();
}
var href = reader.GetRequiredAttribute("href");
var rel = reader.GetRequiredAttribute("rel");
links[rel] = UriConverter.Instance.Convert(href);
await reader.ReadAsync();
break;
case "content":
this.Content = await ParsePropertyValueAsync(reader, 0);
break;
default: throw new InvalidDataException(); // TODO: Diagnostics : unexpected start tag
}
}
reader.EnsureMarkup(XmlNodeType.EndElement, "entry");
await reader.ReadAsync();
if (links != null)
{
this.Links = new ReadOnlyDictionary<string, Uri>(links);
}
}
示例4: ParseDictionaryAsync
static async Task<dynamic> ParseDictionaryAsync(XmlReader reader, int level)
{
var value = (IDictionary<string, dynamic>)new ExpandoObject();
if (!reader.IsEmptyElement)
{
await reader.ReadAsync();
while (reader.NodeType == XmlNodeType.Element && reader.Name == "s:key")
{
string name = reader.GetAttribute("name");
// TODO: Include a domain-specific name translation capability (?)
if (level == 0)
{
switch (name)
{
case "action.email.subject.alert":
name = "action.email.subject_alert";
break;
case "action.email.subject.report":
name = "action.email.subject_report";
break;
case "action.email":
case "action.populate_lookup":
case "action.rss":
case "action.script":
case "action.summary_index":
case "alert.suppress":
case "auto_summarize":
name += ".IsEnabled";
break;
case "alert_comparator":
name = "alert.comparator";
break;
case "alert_condition":
name = "alert.condition";
break;
case "alert_threshold":
name = "alert.threshold";
break;
case "alert_type":
name = "alert.type";
break;
case "coldPath.maxDataSizeMB":
name = "coldPath_maxDataSizeMB";
break;
case "display.visualizations.charting.chart":
name += ".Type";
break;
case "homePath.maxDataSizeMB":
name = "homePath_maxDataSizeMB";
break;
case "update.checksum.type":
name = "update.checksum_type";
break;
}
}
string[] names = name.Split(':', '.');
var dictionary = value;
string propertyName;
dynamic propertyValue;
for (int i = 0; i < names.Length - 1; i++)
{
propertyName = NormalizePropertyName(names[i]);
if (dictionary.TryGetValue(propertyName, out propertyValue))
{
if (!(propertyValue is ExpandoObject))
{
throw new InvalidDataException(); // TODO: Diagnostics : conversion error
}
}
else
{
propertyValue = new ExpandoObject();
dictionary.Add(propertyName, propertyValue);
}
dictionary = (IDictionary<string, object>)propertyValue;
}
propertyName = NormalizePropertyName(names[names.Length - 1]);
propertyValue = await ParsePropertyValueAsync(reader, level + 1);
dictionary.Add(propertyName, propertyValue);
}
reader.EnsureMarkup(XmlNodeType.EndElement, "s:dict");
}
await reader.ReadAsync();
return value; // TODO: what's the type seen by dynamic?
}
示例5: ReadXmlAsync
/// <summary>
/// Asynchronously reads XML data into the current <see cref="AtomFeed"/>.
/// </summary>
/// <exception cref="InvalidDataException">
/// Thrown when an Invalid Data error condition occurs.
/// </exception>
/// <param name="reader">
/// The reader from which to read.
/// </param>
/// <returns>
/// A <see cref="Task"/> representing the operation.
/// </returns>
public async Task ReadXmlAsync(XmlReader reader)
{
Contract.Requires<ArgumentNullException>(reader != null, "reader");
this.Author = null;
this.Entries = null;
this.GeneratorVersion = null;
this.Id = null;
this.Links = null;
this.Messages = null;
this.Pagination = Pagination.None;
this.Title = null;
this.Updated = DateTime.MinValue;
reader.Requires(await reader.MoveToDocumentElementAsync("feed"));
var documentElementName = reader.Name;
List<AtomEntry> entries = null;
Dictionary<string, Uri> links = null;
List<Message> messages = null;
await reader.ReadAsync();
while (reader.NodeType == XmlNodeType.Element)
{
string name = reader.Name;
switch (name)
{
case "title":
this.Title = await reader.ReadElementContentAsync(StringConverter.Instance);
break;
case "id":
this.Id = await reader.ReadElementContentAsync(UriConverter.Instance);
break;
case "author":
await reader.ReadAsync();
reader.EnsureMarkup(XmlNodeType.Element, "name");
this.Author = await reader.ReadElementContentAsync(StringConverter.Instance);
reader.EnsureMarkup(XmlNodeType.EndElement, "author");
await reader.ReadAsync();
break;
case "generator":
// string build = reader.GetRequiredAttribute("build"); // TODO: Incorporate build number? Build number sometimes adds a fifth digit.
string version = reader.GetRequiredAttribute("version");
this.GeneratorVersion = VersionConverter.Instance.Convert(string.Join(".", version));
await reader.ReadAsync();
break;
case "updated":
this.Updated = await reader.ReadElementContentAsync(DateTimeConverter.Instance);
break;
case "entry":
var entry = new AtomEntry();
if (entries == null)
{
entries = new List<AtomEntry>();
}
entries.Add(entry);
await entry.ReadXmlAsync(reader);
break;
case "link":
var href = reader.GetRequiredAttribute("href");
var rel = reader.GetRequiredAttribute("rel");
if (links == null)
{
links = new Dictionary<string, Uri>();
}
links[rel] = UriConverter.Instance.Convert(href);
await reader.ReadAsync();
break;
//.........这里部分代码省略.........