I am new to xpath matching. Here I have a method which pass XML contain as string. I convert it into XmlDocument.
public static void getProjectDataInfo(string content) {
XmlDocument doc = new XmlDocument();
doc.LoadXml(content);
}
Here is my XML. It has xmlns:my
<?xml version="1.0" encoding="UTF-8"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-03T16:54:46" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:Financial>
<my:Quote>
<my:CHARGE_TYPE>MRC</my:CHARGE_TYPE>
<my:Price>463.92</my:Price>
</my:Quote>
</my:Financial>
</my:myField>
I just want to get values of
/my:myFields/my:Financial/my:Quote/my:Price
However I unable to get values hence this XML has xmlns.
Please help me.
Use XmlNamespaceManager
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("ns", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-02-03T16:54:46");
var str = doc.XPathSelectElement("/root/ns:myFields/ns:Financial/ns:Quote/ns:Price", nsmgr)
.ToString(SaveOptions.DisableFormatting);
Console.WriteLine(str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With