-->

How to get text from the node in xml file, that co

2019-09-09 02:49发布

问题:

I have a very big xml file. I read it using by xmlReader. I have problem when i reach to next line:

<title>Abasia<nemod>(-astasia) (hysterical)</nemod></title>

How I can read all that content. I have to have next string at the end: "Abasia (-astasia) (hysterical)".

I tried to use ReadElementContentAsString() for all elements, but elements like this has exception, because it has child element.

help, please=)

回答1:

Could something like this work for you?

XmlNodeList itemNode = xmlDoc.SelectNodes("/");
XmlNode titleNode = itemNode.SelectSingleNode("title");
XmlNode nemodNode = itemNode.SelectSingleNode("nemod");
if((titleNode != null) && (dateNode != null))
    Console.WriteLine(titleNode.InnerText + " " + nemodNode.InnerText);