How to read XML in C# using Xpath

后端 未结 3 756
耶瑟儿~
耶瑟儿~ 2020-12-06 12:18

I have this XML




        
3条回答
  •  青春惊慌失措
    2020-12-06 12:44

    Manipulate XML data with XPath and XmlDocument (C#)

    or

    its better to use LINQ to XML as your are using .net 4.0 and there is no need to learn XPath to traverse the xml tree.

    Not sure about the xpath expression but you can code like this

    string fileName = "data.xml";
    XPathDocument doc = new XPathDocument(fileName);
    XPathNavigator nav = doc.CreateNavigator();
    
    // Compile a standard XPath expression
    XPathExpression expr; 
    expr = nav.Compile("/GetSKUsPriceAndStockResponse/GetSKUsPriceAndStockResult/SKUsDetails/SKUDetails");
    XPathNodeIterator iterator = nav.Select(expr);
    try
    {
      while (iterator.MoveNext())
      {
    
      }
    }
    catch(Exception ex) 
    {
       Console.WriteLine(ex.Message);
    }
    

提交回复
热议问题