2014-09-13 65 views
-1


我想使用LINQ to XML创建具有属性的XML。
如:使用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> 

回答

0

我已经找到了答案here

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