我正在使用System.Xml.Serialization模塊創建一個XML文件。 我有一個類被序列化成一個XML文件。該文件是這樣的:c#使用指定的'encoding'和'stylesheet'行反序列化xml
<itemList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<itemListed>
<item ID="81288" Synopsys="Reset search point" CompletedTime="7/27/10 4:12 PM" Resolver="owner1" />
<item ID="81285" Synopsys="Added contructor" CompletedTime="6/05/10 9:23 AM" Resolver="owner2" />
</itemListed>
</itemList>
問題是,我想它產生這樣的:
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="item.xsl"?>
<itemListed>
<item ID="81288" Synopsys="Reset search point" CompletedTime="7/27/10 4:12 PM" Resolver="owner1" />
<item ID="81285" Synopsys="Added contructor" CompletedTime="6/05/10 9:23 AM" Resolver="owner2" />
</itemListed>
任何想法,我需要改變我的課?
我的代碼:
public class Item { [XmlAttribute("ID")] public string ID { get; set; }
[XmlAttribute("Synopsys")]
public string Synopsys { get; set; }
[XmlAttribute("CompletedTime")]
public string CompletedTime { get; set; }
[XmlAttribute("Resolver")]
public string Resolver { get; set; }
}
public class ItemList
{
[XmlArray(ElementName = "itemListed")]
[XmlArrayItem(ElementName = "item")]
public List<Item> ItemList { get; set; }
}
我感謝所有幫助。 謝謝 託尼
感謝您的建議,但我認爲,我發現和處理問題更簡單的方法。 Tony – tony 2010-07-30 14:12:18
你可以發佈你的答案是什麼,並將其標記爲答案?我對你想出的東西很感興趣。 – 2010-07-30 17:52:30