本文整理汇总了C#中System.Xml.XmlTextWriter.WriteAttributeStringIf方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextWriter.WriteAttributeStringIf方法的具体用法?C# XmlTextWriter.WriteAttributeStringIf怎么用?C# XmlTextWriter.WriteAttributeStringIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteAttributeStringIf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteAsXml
public static void WriteAsXml([NotNull] this Item item, [NotNull] TextWriter writer, [CanBeNull] Action<TextWriter> writeInner = null)
{
var output = new XmlTextWriter(writer);
output.Formatting = Formatting.Indented;
output.WriteStartElement("Item");
output.WriteAttributeString("xmlns", "http://www.sitecore.net/pathfinder/item");
output.WriteAttributeStringIf("Id", item.Uri.Guid.Format());
output.WriteAttributeStringIf("Database", item.DatabaseName);
output.WriteAttributeStringIf("Name", item.ItemName);
output.WriteAttributeStringIf("Path", item.ItemIdOrPath);
output.WriteAttributeStringIf("Template", item.TemplateIdOrPath);
output.WriteStartElement("Fields");
var sharedFields = item.Fields.Where(f => string.IsNullOrEmpty(f.Language) && f.Version == 0).ToList();
var unversionedFields = item.Fields.Where(f => !string.IsNullOrEmpty(f.Language) && f.Version == 0).ToList();
var versionedFields = item.Fields.Where(f => !string.IsNullOrEmpty(f.Language) && f.Version != 0).ToList();
foreach (var field in sharedFields)
{
if (string.Equals(field.TemplateField.Type, "Layout", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Renderings", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Final Renderings", StringComparison.OrdinalIgnoreCase))
{
field.Value.ToXElement()?.WriteTo(output);
continue;
}
output.WriteStartElement("Field");
output.WriteAttributeString("Name", field.FieldName);
output.WriteRaw(EscapeFieldValue(field.Value));
output.WriteEndElement();
}
foreach (var language in unversionedFields.Select(f => f.Language).Distinct())
{
output.WriteStartElement("Unversioned");
output.WriteAttributeString("Language", language);
foreach (var field in unversionedFields.Where(f => f.Language == language))
{
if (string.Equals(field.TemplateField.Type, "Layout", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Renderings", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Final Renderings", StringComparison.OrdinalIgnoreCase))
{
field.Value.ToXElement()?.WriteTo(output);
continue;
}
output.WriteStartElement("Field");
output.WriteAttributeString("Name", field.FieldName);
output.WriteRaw(EscapeFieldValue(field.Value));
output.WriteEndElement();
}
output.WriteEndElement();
}
foreach (var language in versionedFields.Select(f => f.Language).Distinct())
{
output.WriteStartElement("Versioned");
output.WriteAttributeString("Language", language);
foreach (var version in versionedFields.Where(f => f.Language == language).Select(f => f.Version).Distinct())
{
output.WriteStartElement("Version");
output.WriteAttributeString("Number", version.ToString());
foreach (var field in versionedFields.Where(f => f.Language == language && f.Version == version))
{
if (string.Equals(field.TemplateField.Type, "Layout", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Renderings", StringComparison.OrdinalIgnoreCase) || string.Equals(field.FieldName, "__Final Renderings", StringComparison.OrdinalIgnoreCase))
{
field.Value.ToXElement()?.WriteTo(output);
continue;
}
output.WriteStartElement("Field");
output.WriteAttributeString("Name", field.FieldName);
output.WriteRaw(EscapeFieldValue(field.Value));
output.WriteEndElement();
}
output.WriteEndElement();
}
output.WriteEndElement();
}
output.WriteEndElement();
if (writeInner != null)
{
writeInner(writer);
}
output.WriteEndElement();
}