代码
XDocument xdoc = new XDocument(
new XElement("customers",
new XElement("customer",
new XAttribute("ID", "A"),
new XAttribute("City", "New York"),
new XAttribute("Region", "North America"),
new XElement("order",
new XAttribute("Item", "Widget"),
new XAttribute("Price", 100)
),
new XElement("order",
new XAttribute("Item", "Tire"),
new XAttribute("Price", 200)
)
),
new XElement("customer",
new XAttribute("ID", "B"),
new XAttribute("City", "Mumbai"),
new XAttribute("Region", "Asia"),
new XElement("order",
new XAttribute("Item", "Oven"),
new XAttribute("Price", 501)
)
)
)
);

string xmlFileName = @"c:\BegVCSharp\Chapter29\Xml\example2.xml";

xdoc.Save(xmlFileName);

XDocument xdoc2
= XDocument.Load(xmlFileName);

 

 

 

代码
XElement xdoc = XElement.Parse(@"
<customers>
<customer ID=""A"" City=""New York"" Region=""North America"">
<order Item=""Widget"" Price=""100"" />
<order Item=""Tire"" Price=""200"" />
</customer>
<customer ID=""B"" City=""Mumbai"" Region=""Asia"">
<order Item=""Oven"" Price=""501"" />
</customer>
</customers>
");

Console.WriteLine(
"Contents of xdoc:");
Console.WriteLine(xdoc);

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-07-18
  • 2021-12-29
  • 2022-01-01
  • 2021-11-13
  • 2021-06-14
  • 2022-12-23
  • 2021-04-24
猜你喜欢
  • 2022-02-13
  • 2021-12-15
  • 2021-07-03
  • 2021-12-29
  • 2021-11-07
  • 2021-09-29
相关资源
相似解决方案