Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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# Don';t工作的Linq.xml模板_C#_Xml_Linq - Fatal编程技术网

C# Don';t工作的Linq.xml模板

C# Don';t工作的Linq.xml模板,c#,xml,linq,C#,Xml,Linq,我需要从满足条件的XML文件中获取属性列表。例如: <rows> <row code="16" type="M" grv="К"> <cell column="К" dic="s_okved" format="C(8)" inputType="1" vldType="4" vld="pril_okved_11" /> </row> <row code="17" typ

我需要从满足条件的XML文件中获取属性列表。例如:

<rows>    
    <row code="16" type="M" grv="К">
        <cell column="К" dic="s_okved" format="C(8)" inputType="1" vldType="4"
              vld="pril_okved_11" />
    </row>
    <row code="17" type="M" grv="К">
        <cell column="К" dic="s_okved" format="C(8)" inputType="1" vldType="2"
              vld="pril" />
    </row>
</rows>

我觉得这是对的,但它不起作用。有什么想法吗?

你就在附近。尝试:

 XDocument.Parse(xml)
          .Descendants()
          .First(e => e.Attribute("vldType") != null && e.Attribute("vldType").Value == "4")
          .Attribute("vld")
          .Value;
或者如果您使用的是C#6:

在尝试获取测试属性的值之前,需要验证测试属性
vldType
是否存在。如果它不存在,请继续


此外,您可以在此处将
Where
替换为
First
,因为您需要第一个结果。此外,您还可以删除
.Root
.Elements
,然后直接转到
子体

,非常感谢!我错过了生存的支票。Workingtemplate.Root.Elements().subjects()。其中(e=>e.Attribute(“vldType”)!=null和&e.Attribute(“vldType”)。Value==“4”).Attributes(“vld”);如果这个答案解决了你的问题,我将感谢你点击旁边的绿色复选框
 XDocument.Parse(xml)
          .Descendants()
          .First(e => e.Attribute("vldType") != null && e.Attribute("vldType").Value == "4")
          .Attribute("vld")
          .Value;
 XDocument.Parse(xml)
          .Descendants()
          .First(e => e.Attribute("vldType")?.Value == "4")
          .Attribute("vld")
          .Value;