-2

i have a legit XmlNodeList lets call it nodelist
i can call nodelist.ChildNodes and that works
i can also call nodelist.ChildNodes.AsQueryable()
but then when i try nodelist.ChildNodes.AsQueryable().Where(x=>x....) that fails

i have included

using System.Linq

but im kinda at a loss how to
1. find specific nodes
2. count the nodes that start with a specific key ie

<key1 attrib1="xxx">yyy</key1>

how many nodes are there with key="key1"

pls note: before i get yelled at for duplicate posting -
i have spent HOURS over a coupla days trying to figure out how to do this
and nothing on stack has been clear enough (for me anyways...)

thx - you guys are great

UPDATE: ok so whats interesting is that
even tho i got downgraded - nobody (immediately that is) had a solution to my exact question
which is how to do this with xmlnodelist
what people did have were alternate answers - all good
so it doesnt seem that xmlnodelist asqueryable does what the name implies

1) using xmlnode.selectnodes()
which a very good example can be found here
Select Xml Node using Linq to XML

2) XML class (see selected answer)

Community
  • 1
  • 1
toy
  • 422
  • 1
  • 7
  • 19
  • Your questions in the post are not related to title (partially because you don't need to use `AsQueryable` at all to find/count nodes)... Possibly some XML/XPath tutorial is what you need. But if you really looking for `AsQueryable` to be useful you should cast `ChildNodes` to strongly typed enumerable first: `nodelist.ChildNodes.Cast().AsQueryable()` – Alexei Levenkov Nov 17 '14 at 16:24
  • thx @AlexeiLevenkov - yes i could easily be barking up the wrong tree. if there are better ways to do a find/count pls post and i will adjust title. thx! – toy Nov 17 '14 at 16:34
  • It's hard to tell what you're trying to do. You should make a [SSCCE](http://www.sscce.org/), which has **relevant** code that you already have, a clear description about what's failing, and also include exactly what output you want. – Sam I am says Reinstate Monica Nov 17 '14 at 16:46
  • Thanks for title edit. Make sure to remove thank you notes/searched alot from the post as not related. Please check out this search results http://www.bing.com/search?q=c%23+xml+select+nodes to see if you can clarify what information you could not find. Also show sample of different "nodes that start with a specific key" - node in XML have name, namespace, and attributes - but no "key". – Alexei Levenkov Nov 17 '14 at 16:48
  • thx @AlexeiLevenkov - ok so just fyi - i understand that you want the thx/search alot stuff out - but clearly it needed to be stated since ive already been downgraded. also i like to show apprec for peoples knowledge and willingness to help - theres too little of that in the world. and sam - i didnt post an SSCCE originally cause it wasnt necessary within the scope of the orig title. thx alexei for the direction. will go check it out now – toy Nov 17 '14 at 17:15

1 Answers1

1

Attempt to put your XML into a custom class and query the custom class. It's more work, but man is the pay off worth it. Check out this question for info on how to do it.

Community
  • 1
  • 1
Volearix
  • 1,573
  • 3
  • 23
  • 49
  • 1
    thx @volearix! never thought of this concept but its fascinating – toy Nov 18 '14 at 00:25
  • 1
    No problem, it came up as a requirement in a project I was working on recently and really made things much, MUCH easier in the end. – Volearix Nov 18 '14 at 14:29