Page 1 of 1

how to handle XML field names with a dot ? (SOLVED)

Posted: Thursday 24 November 2022 1:31
by willemd
In a DZvents script I am extracting fields from an XML file.

I found that I need to specify the full tree structure, as follows, for example to get the value of position 1:

Code: Select all

domoticz.log('position ' .. item.xml.Publication_MarketDocument.TimeSeries.Period.Point[1].position,domoticz.LOG_INFO)
But now I am really interested in the field called "price.amount" instead of "position". How can I retrieve that one? It contains a "." in the field name !!!!
Is there some kind of escape so I can tell dzvents to ignore the "." and treat "price.amount" as one field name?
Or can I do some kind of conversion in dzvents first to replace the dot by something else (the data is retrieved by a dzvents openURL command).

The XML file is as follows (part of it):

Code: Select all

<Publication_MarketDocument xmlns="urn:iec62325.351:tc57wg16:451-3:publicationdocument:7:0">
<mRID>f301176a2f9c444e9d31cec119e98d81</mRID>
<revisionNumber>1</revisionNumber>
<type>A44</type>
<sender_MarketParticipant.mRID codingScheme="A01">10X1001A1001A450</sender_MarketParticipant.mRID>
<sender_MarketParticipant.marketRole.type>A32</sender_MarketParticipant.marketRole.type>
<receiver_MarketParticipant.mRID codingScheme="A01">10X1001A1001A450</receiver_MarketParticipant.mRID>
<receiver_MarketParticipant.marketRole.type>A33</receiver_MarketParticipant.marketRole.type>
<createdDateTime>2022-11-23T19:34:58Z</createdDateTime>
<period.timeInterval>
<start>2022-11-22T23:00Z</start>
<end>2022-11-23T23:00Z</end>
</period.timeInterval>
<TimeSeries>
<mRID>1</mRID>
<businessType>A62</businessType>
<in_Domain.mRID codingScheme="A01">10YNL----------L</in_Domain.mRID>
<out_Domain.mRID codingScheme="A01">10YNL----------L</out_Domain.mRID>
<currency_Unit.name>EUR</currency_Unit.name>
<price_Measure_Unit.name>MWH</price_Measure_Unit.name>
<curveType>A01</curveType>
<Period>
<timeInterval>
<start>2022-11-22T23:00Z</start>
<end>2022-11-23T23:00Z</end>
</timeInterval>
<resolution>PT60M</resolution>
<Point>
<position>1</position>
<price.amount>155.98</price.amount>
</Point>
<Point>
<position>2</position>
<price.amount>140.64</price.amount>
</Point>

Re: how to handle XML field names with a dot ?

Posted: Thursday 24 November 2022 8:56
by willemd
Solved, I can use the following, with square brackets and quotes and without a dot between [id] and ['price.amount']

Code: Select all

domoticz.log('position ' .. item.xml.Publication_MarketDocument.TimeSeries.Period.Point[id]['price.amount'],domoticz.LOG_INFO)