1

I was given a web service that I have to use to pull data into a table. Right now it pulls all nodes, but I would like to pull only the nodes with Web.

Searching the web, I can only find examples of how to do this if there is an attribute, which there is not. This is what I have so far, and can't seem to figure out what to do next -

XmlNodeList records = root.SelectNodes("descendant::record[//@Origin=Web]");

Also tried -

XmlNodeList records = xmldoc.SelectNodes("/Results/Record/Origin['=Web']");

Edit - I'm aware that neither of the above attempts are even remotely close to working

Edit 2 - XML is set up like this -

<results>
  <record>
    <name></name>
    <email></email>
    <origin></origin>
  </record>
</results>

1 Answer 1

4

You can do it with this XPath:

//origin[text()="web"]

It means select all origin elements (regardless of hierarchy) where the inner text is web.

So, your statement becomes now:

XmlNodeList records = xmldoc.SelectNodes("//origin[text()='web']");
Sign up to request clarification or add additional context in comments.

23 Comments

Which of the above examples should I use this with?
Unfortunately that's exactly what I had, and it's not working for some reason. Not sure if this makes a difference, but I looking at the web service, it shows the origin like this - <origin><![CDATA[Web]]></origin> Would this change the answer?
@user3869708: OK, so the actual problem is that you have no origin elements that contain web?
Apparently not, I now see that it is displayed as <![CDATA[Web]]>
is there a different route to take?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.