I have an XML file looking like this:
<xc:XmlCache xmlns:xc="XmlCache" xmlns:mp="mx.MarketParameters" xmlns:rt="mx.MarketParameters.Rates" xmlns:rtcu="mx.MarketParameters.Rates.Curve">
<xc:XmlCacheArea xc:value="MarketParameters">
<mp:nickName xc:value="MDS" xmlns:mp="mx.MarketParameters">
<mp:date xc:value="20160518">
<rt:rate xmlns:rt="mx.MarketParameters.Rates">
<rtcu:curve xmlns:rtcu="mx.MarketParameters.Rates.Curve">
<rtcu:currency xc:value="AED">
<rtcu:label xc:value="AED FX">
<rtcu:type xc:value="Swap point">
<rtcu:generator xc:value="USD/AED">
<rtcu:market xc:value="">
<rtcu:maturity xc:value="10M" xc:dates="20160523-20170323" xc:type="Fields">
I would like to get a list of nodes of type rtcu:maturity
in VBA to perform some operations:
Dim xmlCurvesFileDOMDocument As New DOMDocument60
Dim listOfMaturities As IXMLDOMNodeList
xmlCurvesFileDOMDocument.Load (xmlCurvesFilePath)
Set listOfMaturities = xmlCurvesFileDOMDocument.SelectNodes("//xc:XmlCache/xc:XmlCacheArea/mp:nickName/mp:date/rt:rate/rtcu:curve/rtcu:currency/rtcu:label/rtcu:type/rtcu:generator/rtcu:market/rtcu:maturity")
(note: I'm omitting xmlCurvesFilePath
but it's correct, the file is loaded).
When I run this, on the set of listOfMaturities
I get an error of type Reference to undeclared namespace prefix: 'xc'
. If I remove xc
from the path, it will tell me the problem is the other one (mp
). If I remove all the namespaces from the XPath, it works but it loads nothing.
I've tried to search stack overflow and it seems that the solution would be to set the Selection Name spaces (like here and here).
However, when I try to do that:
xmlCurvesFileDOMDocument.setProperty("SelectionNamespaces", "xmlns:xc='XmlCache'")
... I get a compile error telling me "Expected : =
".
Does anyone have an idea on how I can declare my namespaces and parse this XML file?