0

I want to read a certain XmlNode from a XmlTextReader. My file looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<data>
   <legend>
      <element>
         <tag> aqua </tag>
...

while the "aqua" text is surrounded by "/r/n". So I tried to read it somehow like:

dataNode.SelectNodes("//legend/element").where("Tag".Trim() == "aqua");

of course this is just scrap and not working so I need the right one.

Can someone name the right XPath pattern ?

dirkk
  • 6,160
  • 5
  • 33
  • 51
JJB2
  • 53
  • 1
  • 5
  • This is not valid XML, a tag name has to immediately follow a `<`, e.g. `` instead of `< data >`. I don't know if this is really your source file or just bad formatting here. Also, your shortening is not really good, as you are missing all the closing tags (thus making it invalid XML). Furthermore, what is "/r/n" you are talking about - I don't see it anywhere. – dirkk Jul 31 '14 at 10:19
  • As I wrote, this is just scrap. The XML is just partially pasted. And I needed to separate the <> from the text to prevent the edit control from cutting it out of the post. And of course I didn't paste the /r/n, which you wouldn't see anyway. – JJB2 Aug 01 '14 at 05:57
  • This is blatently wrong. I just edited your question, there is no problem if you remove the space. Please format your XML properly, in this case it is not just nicer-looking, it is **required** so the XML is valid. Also, you **need* closing tags, e.g. it is ` aqua ` or ` aqua `? With /r/nT do you mean a line break? I have never seen it with normal slashes, it should be \r\n – dirkk Aug 01 '14 at 06:09
  • You're right. Sloppy jotting me. Of course \ not /. Happily Martin got what I meant. Issue closed. PS: "Browser" not equals "Browser". Don't ask why ! – JJB2 Aug 01 '14 at 07:26

1 Answers1

1

As an XPath 1.0 expression I think you want //legend/element[tag[normalize-space() = 'aqua']]. That selects element elements that have a tag child elements whose normalized string value is aqua.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110