【发布时间】:2020-06-30 07:10:51
【问题描述】:
我想使用 Linq(如果可以的话)从数据库中的数据自动创建一个 XML。 为此,我的理解是需要占位符。 你如何插入这些占位符? 我已经向您展示了我的示例 XML,我想保留这种格式。 (除非它不起作用) 我期待您的回答,并在此先感谢您。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.Schema;
namespace LinqToXML1._1
{
class Program
{
static void Main(string[] args)
{
XDocument exampleDocument= new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement("VN_Nr", new XAttribute("VN_Nr(placeholder int)",11),
new XElement("EI Nubmer" ,3, new XAttribute("NL Number","EI Number(placeholder int) 0000")),
new XElement("Serialnumber", 0),
new XElement("GM Number(placeholder int)",2),
new XElement("FW Number (placeholder string)")
)
); // Safe file.
exampleDocument.Save(@"C:");
Console.WriteLine(exampleDocument.ToString());
}
}
}
【问题讨论】:
-
您期望的 XML 是什么?属性不能使用
(,它是特殊字符。