Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将xml解析到字典中_C#_Dictionary_Linq To Xml - Fatal编程技术网

C# 将xml解析到字典中

C# 将xml解析到字典中,c#,dictionary,linq-to-xml,C#,Dictionary,Linq To Xml,我正在尝试将XML文件解析到字典中。 问题是我在网上找到的所有解决方案都显示了如何通过搜索name元素来实现这一点。我要搜索的是我的应用程序名称元素本身 <?xml version="1.0" encoding="UTF-8"?> <calibration> <ZoomLevel 250="0.0100502512562814" /> <ZoomLevel 251="0.0100502512562814" />

我正在尝试将XML文件解析到字典中。 问题是我在网上找到的所有解决方案都显示了如何通过搜索name元素来实现这一点。我要搜索的是我的应用程序名称元素本身

<?xml version="1.0" encoding="UTF-8"?>
    <calibration>
      <ZoomLevel 250="0.0100502512562814" />
      <ZoomLevel 251="0.0100502512562814" />
      <ZoomLevel 252="0.0100502512562814" />
      <ZoomLevel 253="0.0100502512562814" />
      <ZoomLevel 254="0.0100502512562814" />
      <ZoomLevel 255="0.0100502512562814" />
      <ZoomLevel 256="0.0100502512562814" />
      <ZoomLevel 257="0.0100502512562814" />
</calibration>

我希望删除键“250、251等”和值并创建字典


抱歉,如果这是一个愚蠢的问题,但我是c#的新手,我很难做到这一点

不幸的是,您的XML不是有效的。属性名称不能从数字开始

但是,为了展示当XML有效时如何实现,让我们假设它看起来是这样的:

<?xml version="1.0" encoding="UTF-8"?>
    <calibration>
      <ZoomLevel _250="0.0100502512562814" />
      <ZoomLevel _251="0.0100502512562814" />
      <ZoomLevel _252="0.0100502512562814" />
      <ZoomLevel _253="0.0100502512562814" />
      <ZoomLevel _254="0.0100502512562814" />
      <ZoomLevel _255="0.0100502512562814" />
      <ZoomLevel _256="0.0100502512562814" />
      <ZoomLevel _257="0.0100502512562814" />
</calibration>

a.Name.LocalName.Substring(1)
跳过属性名称中的第一个字符-

很遗憾,您的XML不是有效的XML。属性名称不能从数字开始

但是,为了展示当XML有效时如何实现,让我们假设它看起来是这样的:

<?xml version="1.0" encoding="UTF-8"?>
    <calibration>
      <ZoomLevel _250="0.0100502512562814" />
      <ZoomLevel _251="0.0100502512562814" />
      <ZoomLevel _252="0.0100502512562814" />
      <ZoomLevel _253="0.0100502512562814" />
      <ZoomLevel _254="0.0100502512562814" />
      <ZoomLevel _255="0.0100502512562814" />
      <ZoomLevel _256="0.0100502512562814" />
      <ZoomLevel _257="0.0100502512562814" />
</calibration>

a.Name.LocalName.Substring(1)
跳过属性名中的第一个字符-

您的XML以-250开头是无效的属性名。(您还需要清楚属性和元素之间的区别。这里的元素是
ZoomLevel
;属性是
250=“…”
部分。)是否删除键?能否给出字典中键值对的示例?XML开头无效-250不是有效的属性名。(您还需要清楚属性和元素之间的区别。这里的元素是
ZoomLevel
;属性是
250=“…”
部分。)是否删除键?你能举一个字典中键值对的例子吗?