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

五迷三道 提交于 2019-12-12 03:03:18

问题


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


来源:https://stackoverflow.com/questions/16659546/how-to-get-text-from-the-node-in-xml-file-that-contains-text-and-child-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!