<Account nr="401" name="Wasser/Abwasser" income="0.00" expenditure="1,310.74" saldo="-1,310.74" resultText="Es wurden ausgegeben">
<Accounting date="15.02." refNr="....." description="I/2013" income="" expenditure="1,310.74" vat="10%" pretax="131.07"/>
</Account>
我可以使用 XmlTextWriter 但不知道如何继续使用 nr,name.....
myXmlTextWriter.WriteStartElement("Account");.....
myXmlTextWriter.WriteElementString("Accounting",......
谢谢
最佳答案
尝试使用 XElement
结束 XAttribute
类。它们是 LINQ to XML 的一部分,它们使使用 XML 变得更加容易。
var xml = new XElement("Account",
new XAttribute("nr", 401),
new XAttribute("name", "Wasser/Abwasser"),
new XElement("Accounting",
new XAttribute("date", "15.02."),
new XAttribute("refNr", "...")));
那个在 .ToString()
上返回:
<Account nr="401" name="Wasser/Abwasser">
<Accounting date="15.02." refNr="..." />
</Account>
按照模式填充其余属性,您将拥有所需的内容。
关于c# - 如何在 C# 中编写 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787435/