我想將以下標籤寫入XML文件。C#XmlWriter WriteStartAttribute
<StructureMetaData xsi:schemaLocation="MSD" xmlns="MSD" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- here a following more tags -->
</StructureMetaData>
這些我下面
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t"
CheckCharacters = false,
};
XmlWriter xmlWriter = XmlWriter.Create (filename, settings);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartAttribute ("xsi", "schemaLocation", "MSD");
xmlWriter.WriteStartAttribute ("xmlns", "MSD");
xmlWriter.WriteStartAttribute ("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-instance");
但WriteStartAttribute的第一個電話後,我得到了以下異常:
「令牌StartAttribute狀態文件將導致無效的XML文檔「。
如何將這些屬性寫入xml標籤?
謝謝,它的工作原理。但與子項我有一個XML問題。我得到以下內容: ABC 123 456 789 StructureMetaData> 我將讀取如何產生與LINQ的XML文件。每個XElement都有一個xmlns屬性。 –
Holgis
我更新了代碼。 – jdweng