Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Linq to XML创建具有属性的XML树_C# - Fatal编程技术网

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")));