我不知道为什么无论如何我都无法完成这项工作。我的代码:using System;using System.Linq;using System.Xml.Linq;namespace XML_TESTER_CM{ internal class Program { private static void Main(string[] args) { XDocument xDoc; xDoc = XDocument.Load("Palette_Sets.xml"); var result1 = xDoc.Descendants("SETS"); var result2 = xDoc.Descendants("PALETTE"); var result3 = xDoc.Descendants("COLOR"); } }}我的XML文件:https: //pastecode.xyz/view/25d53914<?xml version="1.0" encoding="utf-8"?> <SETS> <PALETTE id="Default Set"> <COLOR> <Name>Red</Name> <RGBString>#FF0000</RGBString> </COLOR> <COLOR> <Name>Blue</Name> <RGBString>#0000FF</RGBString> </COLOR> <COLOR> <Name>Cyan</Name> <RGBString>#00FFFF</RGBString> </COLOR> <COLOR> <Name>Magenta</Name> <RGBString>#FF00FF</RGBString> </COLOR> <COLOR> <Name>Green</Name> <RGBString>#00FF00</RGBString> </COLOR> <COLOR> <Name>Orange</Name> <RGBString>#FFAA00</RGBString> </COLOR> <COLOR> <Name>Yellow</Name> <RGBString>#FFFF00</RGBString> </COLOR> </PALETTE> <PALETTE id="OLD Set"> <COLOR> <Name>Olive</Name> <RGBString>#7f8229</RGBString> </COLOR> <COLOR> <Name>Dark Blue</Name> <RGBString>#272c72</RGBString> </COLOR> <COLOR> <Name>Silver</Name> <RGBString>#9597af</RGBString> </COLOR> </PALETTE></SETS>xDoc可以正确返回文档,但是Descendants方法根本不起作用,每个resultX var都有一个空的结果视图。
1 回答
- 1 回答
- 0 关注
- 154 浏览
添加回答
举报
0/150
提交
取消