我在 c# 中有以下代码,我正在尝试生成 xml。
foreach (Component compCategories in categories)
{
GenerateXML(xml, compCategories);
}
private void GenerateXML(XmlWriter xml, Component compCategory)
{
xml.WriteStartElement("category");
xml.WriteAttributeString("id", compCategory.Id.ItemId.ToString());
字符串顺序 = compCategory.Title;
xml.WriteAttributeString("order", order);
Component detailCategory = compCategory.ComponentValue("Detail");
if (detailCategory != null)
{
xml.WriteAttributeString("detail", detailCategory.Id.ItemId.ToString());
}
Component catArtwork = compCategory.ComponentValue("Artwork");
if (catArtwork != null)
{
Component summaryArtwork = catArtwork.ComponentValue("Summary");
if (summaryArtwork != null)
{
String CatImageUrl = PublishBinary(summaryArtwork);
xml.WriteAttributeString("image", CatImageUrl);
}
}
xml.WriteElementString("title", compCategory.StringValue("Title").ToString());
xml.WriteElementString("summary", compCategory.StringValue("Summary").ToString());
xml.WriteElementString("linktext", compCategory.StringValue("Linktext").ToString());
xml.WriteEndElement();
}
如何根据“order”(上面突出显示)属性值对 xml 渲染进行排序,我不打算使用 XSLT,但是 LINQ 很好。
请推荐!!
谢谢