混合了xml中的属性和元素

时间:2013-03-21 15:29:10

标签: c# xml

我需要在下面的结构中创建一个xml。

<ipaddress> "10.10.10.10" </ipaddress> 
<PipeId pid = "4598702C-691E">testvalue</PipeId> --how to display this?
<name> "testname" </name> 

但我对xml中的第二行感到困惑。如何显示?

我尝试了以下代码..但是不知道如何将第二行放入xml ..

new XElement("StartElement",
new XAttribute("TestAtt", "some & value"),
new XElement("ipaddress", "10.10.10.10"),
new XElement("name", "testname")));

1 个答案:

答案 0 :(得分:2)

如果您只是想构建该元素,那么您需要:

new XElement("PipeId",                       // Name of the element
    new XAttribute("pid", "4598702C-691E"),  // Attribute of the element
    "testvalue")                             // Text content of the element
相关问题