c#xml字符串解析
<root><channels><channel><ID>01</ID><pressure>18</pressure></channel><channel><ID>02<...
<root>
<channels>
<channel>
<ID>01</ID>
<pressure>18</pressure>
</channel>
<channel>
<ID>02</ID>
<pressure>20</pressure>
</channel>
</channels>
</root> 展开
<channels>
<channel>
<ID>01</ID>
<pressure>18</pressure>
</channel>
<channel>
<ID>02</ID>
<pressure>20</pressure>
</channel>
</channels>
</root> 展开
1个回答
展开全部
using System.Xml.Linq;
XElement xmlTree2 = XElement.Load("文件路径");
XElement channels=xmlTree2.Element("channels");
foreach (var item in channels.Element("channel"))
{
Console.WriteLine(item.Element("ID") );
Console.WriteLine(item.Element("pressure"));
}
更多追问追答
追问
不涉及文件路径,只是xml字符串
追答
XElement xmlTree2 = XElement.
Parse
(@"<root>
<channels>
<channel>
<ID>01</ID>
<pressure>18</pressure>
</channel>
<channel>
<ID>02</ID>
<pressure>20</pressure>
</channel>
</channels>
</root>");
第一句改了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询