XML deserialize

Hi all,

I have some XML (listed below), from which I need to extract some attribute values.

The element from which I need to extract is shown below, and I need the values from the “value” attributes of the generic:ObsDimension and generic:ObsValue elements.

<generic:Obs>
  <generic:ObsDimension value="2018-12-20"/>
  <generic:ObsValue value="7.4672"/>
  <generic:Attributes>
    <generic:Value id="OBS_STATUS" value="A"/>
    <generic:Value id="OBS_CONF" value="F"/>
  </generic:Attributes>
</generic:Obs>

I’ve tried a number of things, but this XML-parsing thing is new to me, so if anyone has a “this is how I’d do it”, it would be appreciated. For example example extracting the data to a datatable.

I have watched dozens of youtube tutorials, so no need to post more of those :slight_smile:

Thanks.

Full XML document sample:

<?xml version="1.0" encoding="UTF-8"?><message:GenericData xmlns:message="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:common="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:generic="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic" xsi:schemaLocation="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message https://sdw-wsrest.ecb.europa.eu:443/vocabulary/sdmx/2_1/SDMXMessage.xsd http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common https://sdw-wsrest.ecb.europa.eu:443/vocabulary/sdmx/2_1/SDMXCommon.xsd http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/generic https://sdw-wsrest.ecb.europa.eu:443/vocabulary/sdmx/2_1/SDMXDataGeneric.xsd">
<message:Header>
<message:ID>75236374-ddb5-4209-a450-c68408287fdd</message:ID>
<message:Test>false</message:Test>
<message:Prepared>2020-12-17T07:14:24.145+01:00</message:Prepared>
<message:Sender id="ECB"/>
<message:Structure structureID="ECB_EXR1" dimensionAtObservation="TIME_PERIOD">
<common:Structure>
<URN>urn:sdmx:org.sdmx.infomodel.datastructure.DataStructure=ECB:ECB_EXR1(1.0)</URN>
</common:Structure>
</message:Structure>
</message:Header>
<message:DataSet action="Replace" validFromDate="2020-12-17T07:14:24.145+01:00" structureRef="ECB_EXR1">
<generic:Series>
<generic:SeriesKey>
<generic:Value id="FREQ" value="D"/>
<generic:Value id="CURRENCY" value="DKK"/>
<generic:Value id="CURRENCY_DENOM" value="EUR"/>
<generic:Value id="EXR_TYPE" value="SP00"/>
<generic:Value id="EXR_SUFFIX" value="A"/>
</generic:SeriesKey>
<generic:Attributes>
<generic:Value id="COLLECTION" value="A"/>
<generic:Value id="UNIT" value="DKK"/>
<generic:Value id="TIME_FORMAT" value="P1D"/>
<generic:Value id="TITLE_COMPL" value="ECB reference exchange rate, Danish krone/Euro, 2:15 pm (C.E.T.)"/>
<generic:Value id="TITLE" value="Danish krone/Euro"/>
<generic:Value id="UNIT_MULT" value="0"/>
<generic:Value id="SOURCE_AGENCY" value="4F0"/>
<generic:Value id="DECIMALS" value="4"/>
</generic:Attributes>
<generic:Obs>
<generic:ObsDimension value="2018-12-20"/>
<generic:ObsValue value="7.4672"/>
<generic:Attributes>
<generic:Value id="OBS_STATUS" value="A"/>
<generic:Value id="OBS_CONF" value="F"/>
</generic:Attributes>
</generic:Obs>
<generic:Obs>
<generic:ObsDimension value="2018-12-21"/>
<generic:ObsValue value="7.467"/>
<generic:Attributes>
<generic:Value id="OBS_STATUS" value="A"/>
<generic:Value id="OBS_CONF" value="F"/>
</generic:Attributes>
</generic:Obs>
</generic:Series>
</message:DataSet>
</message:GenericData>

Hi,

You need to handle xml namespace.
Hope the following sample helps you.

Sample20201217-1.zip (3.5 KB)

Regards,

2 Likes

Thank you!! This was (almost) exactly what I needed. I have modified my code a little, so it loops through the “Obs” nodes and then lists the ObsDimension and then ObsValue for that Obs-node, and then moves on to the next Obs.

Screenshot below and new Main.xaml attached.

-Jeppe

Main.xaml (9.5 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.