I tried to parse an XML file: http://www.ikea.com/pl/pl/catalog/products/30198858?type=xml&dataset=normal,parentCategories,allImages but I obtained error
Namespace Manager or XlstContext needed. This query has a prefix, variable or user-definde function."
Code:
XPathDocument oXPathDocument = new XPathDocument(path);
XPathNavigator oXPathNameNavigator = oXPathDocument.CreateNavigator();
XPathNodeIterator oProductNodesIterator = oXPathNameNavigator.Select(@"/ikea-rest/products/product/items/item");
productModel.productName = oXPathNameNavigator.SelectSingleNode("name").Value;
I found that this error is being caused by lack of namespace so I tried to add it like this:
XmlNamespaceManager nameSpace = new XmlNamespaceManager(oXPathNameNavigator.NameTable);
nameSpace.AddNamespace("ir",path);
Now I have new error:"System.NullReferenceException: Object reference not set to an instance of an object." in line:
productModel.productName = oXPathNameNavigator.SelectSingleNode("name").Value;
What's wrong with my code?