I’ve got a problem with the following, let’s consider this XML document :
<FEATURE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<LINES xmlns="namespace1">
<LINE>
<AMOUNT>5000</AMOUNT>
......
</LINE>
<LINE>
<AMOUNT>6000</AMOUNT>
</LINE>
</LINES>
</FEATURE>
I can’t figure out how to modify for exemple the AMOUNT value of the first LINE.
I have tried many things, like the following :
var doc = XDocument.Load(doc);
var xmn = new XmlNamespaceManager(new NameTable());
xmn.AddNamespace(string.Empty, "namespace1");
var element = doc.XPathSelectElement("/FEATURE/LINES/LINE[1]", xmn);
element is always null and I can’t figure out why. I have tried this : http://www.xmlplease.com/update-xml-linq with removing the id attribute the XPath /products/product[1] works great…
Any advice would be appreciated.
giving the default NS a name
and writing xpath like this
worked for me 🙂