C# 使用Linq to XML创建具有属性的XML树
C# 使用Linq to XML创建具有属性的XML树,c#,C#,我想使用LINQ to XML创建具有属性的XML。 例如: 我找到了答案: <class name="Pessoa" tabela="pessoa"> <property name="id" column="id" pk="true"/> <property name="nome" column="nome"/> <property name="genero" column="genero"/> <prop
我想使用LINQ to XML创建具有属性的XML。
例如:
我找到了答案:<class name="Pessoa" tabela="pessoa">
<property name="id" column="id" pk="true"/>
<property name="nome" column="nome"/>
<property name="genero" column="genero"/>
<property name="dataNasc" column="data_nasc" type="date"/>
</class>
XElement n = new XElement("class",
new XElement("property",
new XAttribute("name", "id"),
new XAttribute("column", "id")),
new XElement("property",
new XAttribute("name", "dataNasc"),
new XAttribute("column", "data_nasc"),
new XAttribute("pk", "true")));