我有一个用于在 c# 中构建 xml 站点地图的类,我在 mvc 控制器中使用它来生成站点地图:
public class Location
{
public enum eChangeFrequency
{
always,
hourly,
daily,
weekly,
monthly,
yearly,
never
}
[XmlElement("loc")]
public string Url { get; set; }
[XmlElement("changefreq")]
public eChangeFrequency? ChangeFrequency { get; set; }
public bool ShouldSerializeChangeFrequency() { return ChangeFrequency.HasValue; }
[XmlElement("lastmod")]
public DateTime? LastModified { get; set; }
public bool ShouldSerializeLastModified() { return LastModified.HasValue; }
[XmlElement("priority")]
public double? Priority { get; set; }
public bool ShouldSerializePriority() { return Priority.HasValue; }
[XmlElement("image")]
public Image Image { get; set; }
}
[XmlType("image")]
public class Image
{
[XmlElement(ElementName = "loc")]
public string UrlLocation { get; set; }
[XmlElement(ElementName = "caption")]
public string Caption { get; set; }
[XmlElement(ElementName = "title")]
public string Title { get; set; }
}
这是输出,当我使用它时:
<url>
<loc>http://...</loc>
<priority>0.5</priority>
<image>
<loc>http://...</loc>
</image>
</url>
但我想要正确的格式,像这样:
<url>
<loc>http://...</loc>
<priority>0.5</priority>
<image:image>
<image:loc>http://...</image:loc>
</image:image>
</url>
我想将此前缀添加到图像元素,感谢您的帮助