【发布时间】:2015-12-22 18:25:07
【问题描述】:
XML 示例:
<?xml version="1.0" encoding="utf-8" ?>
<brand name="brand1" num_brand="118" enabled="True">
<price>
<nodePattern>pattern</nodePattern>
<attribute type="text" ></attribute>
<treatment enabled="1" type="Regex">reg</treatment>
</price>
<title>
<nodePattern>pattern</nodePattern>
<attribute type="text" ></attribute>
<treatment enabled="1" type="Regex">reg</treatment>
</title>
</brand>
请问,如何使用 System.Xml.Linq 获取所有不同节点的不同属性值和文本(例如 name、num_brand 和 enabled for brand、enabled、type 和 "reg" for treatment)?
谢谢!
【问题讨论】:
-
到目前为止你尝试过什么?你在挣扎什么?您想如何获取这些值(在单个字符串中?加载到类中?)
-
现在的问题是你的问题是什么?根据您的需要,Linq to XML 非常简单。例如
var x = doc.Root.Attribute("num_brand").Value;为您提供该属性的文本..