I have this .xml file:
<P48Cierre xmlns="http://sujetos.esios.ree.es/schemas/2007/03/07/P48Cierre-esios-MP/">
<IdentificacionMensaje v="p48cierre_20160101"/>
<VersionMensaje v="1"/>
<TipoMensaje v="Z66"/>
<TipoProceso v="Z04"/>
<TipoClasificacion v="A01"/>
<IdentificacionRemitente v="10XES-REE------E" codificacion="A01"/>
<FuncionRemitente v="A04"/>
<IdentificacionDestinatario v="DESTINATARIO" codificacion="A01"/>
<FuncionDestinatario v="A08"/>
<FechaHoraMensaje v="2016-01-02T01:17:30Z"/>
<Horizonte v="2015-12-31T23:00Z/2016-01-01T23:00Z"/>
<SeriesTemporales>
<IdentificacionSeriesTemporales v="STP0"/>
<TipoNegocio v="Z21"/>
<UPEntrada v="ESANAG" codificacion="NES"/>
<UnidadMedida v="MWH"/>
<Periodo>
<IntervaloTiempo v="2015-12-31T23:00Z/2016-01-01T23:00Z"/>
<Resolucion v="PT60M"/>
<Intervalo>
<Pos v="1"/>
<Ctd v="14.6"/>
</Intervalo>
</Periodo>
</SeriesTemporales>
<SeriesTemporales>
<IdentificacionSeriesTemporales v="STP1"/>
<TipoNegocio v="Z21"/>
<UPEntrada v="ETINEO" codificacion="NES"/>
<UnidadMedida v="MWH"/>
<Periodo>
<IntervaloTiempo v="2015-12-31T23:00Z/2016-01-01T23:00Z"/>
<Resolucion v="PT60M"/>
<Intervalo>
<Pos v="23"/>
<Ctd v="41.7"/>
</Intervalo>
<Intervalo>
<Pos v="24"/>
<Ctd v="41.6"/>
</Intervalo>
</Periodo>
</SeriesTemporales>
</P48Cierre>
I need an excel output table like this:
UPEntrada | Pos | Ctd |
---|---|---|
ESANAG | 1 | 14.6 |
ETINEO | 23 | 41.7 |
ETINEO | 24 | 41.6 |
I have tried accesing the nodes following this method found on the web:
Sub XMLParse()
Dim oXml As New MSXML2.DOMDocument60
Dim lNodes As IXMLDOMNodeList, xNode As IXMLDOMNode
oXml.Load ("C:\archive.xml")
With oXml.DocumentElement
Set lNodes = .SelectNodes("SeriesTemporales")
End With
For Each xNode In lNodes
With xNode
Debug.Print .ParentNode.nodeName & "/" & .nodeName & " : " & .Text
End With
Next xNode
End Sub
However, xNode is always empty no matter what I put in Set lNodes = .SelectNodes("*") and the compilator never enters in the For part of the code.
Could you help me please? Thanks in advance
EDIT: I have tried the solution of @barrowc and it works perfect:
Sub XMLParse()
Dim oXml As New MSXML2.DOMDocument60
Dim lNodes As IXMLDOMNodeList, xNode As IXMLDOMNode
oXml.SetProperty "SelectionNamespaces", "xmlns:r='http://sujetos.esios.ree.es/schemas/2007/03/07/P48Cierre-esios-MP/'"
oXml.async = False
oXml.Load ("C:archivo.xml")
Set lNodes = oXml.SelectNodes("/r:P48Cierre/r:SeriesTemporales/r:Periodo/r:Intervalo/r:Pos")
For Each xNode In lNodes
With xNode
Debug.Print .ParentNode.nodeName & "/" & .nodeName & " : " & .Attributes.Item(0).NodeValue
End With
Next xNode
End Sub