Search code examples
c#xmlxmlreaderxmlnode

How to get text from the node in xml file, that contains text and child node?


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=)


Solution

  • 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);