How to get element content using only XPath and C# .NET

前端 未结 3 1441
粉色の甜心
粉色の甜心 2021-01-13 23:56

I\'ve found a lot of articles about how to get node content by using simple XPath expression and C#, for example:

XPath:

/bookstore/author/first-nam         


        
3条回答
  •  不要未来只要你来
    2021-01-14 00:20

    After googling c# .net xpath for few seconds you'll find this article, which provides example which you can easily modify to use XPathDocument, XPathNavigator and XPathNavigator::SelectSingleNode():

    XPathNavigator nav;
    XPathDocument docNav;
    string xPath;
    
    docNav = new XPathDocument("c:\\books.xml");
    nav = docNav.CreateNavigator();
    xPath = "/Cell/CellContent/Para/ParaLine/String/text()";
    
    string value = nav.SelectSingleNode(xPath).Value
    

    I recommend more reading on xPath syntax. Much more.

提交回复
热议问题