Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
356 views
in Technique[技术] by (71.8m points)

c# - 如何通过附加值选择多个XML标记作为XElement?(How to Select Multiple XML tags as XElement By attatribute value?)

How to select Multiple XML Tags as XElement , filtering based on same attribute.

(如何选择多个XML标签作为XElement ,如何基于相同的属性进行过滤。)

I have Below code i want to select tags with are having action=true

(我有以下代码我想选择具有action = true的标签)

<root>
  <first action="true">
    <path>E:Myfolder</path>
  </first>
  <second>
    <path>C:Users</path>
  </second>
  <third action="true">
    <name>Mytasks</name>
  </third>
</root>

and Output shout be like this

(和输出喊像这样)

  <first action="true">
    <path>E:Myfolder</path>
  </first>
  <third action="true">
    <name>Mytasks</name>
  </third>

anybody please help me.

(有人请帮助我。)

I used FirstorDefault( ) But i am getting only one record among all

(我使用了FirstorDefault( ),但是我只得到了一条记录)

  ask by Prashanth Reddy Balemula translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

尝试这个

xd = XDocument.Load("XML FILE PATH"); xe = xd.Root; IEnumerable<XElement> oColl = from x in xe.Descendants() where ((string)x.Attribute("action")).equals("true") select x;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...