Я пытаюсь получить данные от Европейского центрального банка (ЕЦБ) через эту конечную точку: https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
Я создал структуру, соответствующую элементам XML. Однако дочерние узлы не отображаются. Я использую не тот элемент? Вот структура (ы).
Xml:
<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time="2018-04-30">
<Cube currency="USD" rate="1.2079"/>
<Cube currency="JPY" rate="132.12"/>
<Cube currency="BGN" rate="1.9558"/>
<Cube currency="CZK" rate="25.542"/>
<Cube currency="DKK" rate="7.4501"/>
<Cube currency="GBP" rate="0.87960"/>
<Cube currency="HUF" rate="313.55"/>
<Cube currency="PLN" rate="4.2264"/>
<Cube currency="RON" rate="4.6614"/>
<Cube currency="SEK" rate="10.4993"/>
<Cube currency="CHF" rate="1.1968"/>
<Cube currency="ISK" rate="122.20"/>
<Cube currency="NOK" rate="9.6620"/>
<Cube currency="HRK" rate="7.4100"/>
<Cube currency="RUB" rate="75.9587"/>
<Cube currency="TRY" rate="4.8896"/>
<Cube currency="AUD" rate="1.6013"/>
<Cube currency="BRL" rate="4.1932"/>
<Cube currency="CAD" rate="1.5542"/>
<Cube currency="CNY" rate="7.6574"/>
<Cube currency="HKD" rate="9.4801"/>
<Cube currency="IDR" rate="16796.15"/>
<Cube currency="ILS" rate="4.3378"/>
<Cube currency="INR" rate="80.1685"/>
<Cube currency="KRW" rate="1292.04"/>
<Cube currency="MXN" rate="22.5977"/>
<Cube currency="MYR" rate="4.7409"/>
<Cube currency="NZD" rate="1.7145"/>
<Cube currency="PHP" rate="62.452"/>
<Cube currency="SGD" rate="1.6016"/>
<Cube currency="THB" rate="38.145"/>
<Cube currency="ZAR" rate="15.0121"/>
</Cube>
</Cube>
</gesmes:Envelope>
Классы:
<XmlRootAttribute([ElementName]:="Sender", [Namespace]:="http://www.gesmes.org/xml/2002-08-01")>
Public Class Sender
<XmlElement([ElementName]:="name", [Namespace]:="http://www.gesmes.org/xml/2002-08-01")>
Public Property Name As String
End Class
<XmlRootAttribute([ElementName]:="Cube", [Namespace]:="http://www.ecb.int/vocabulary/2002-08-01/eurofxref")>
Public Class Cube
<XmlAttribute([AttributeName]:="name")>
Public Property Currency As String
<XmlAttribute([AttributeName]:="rate")>
Public Property Rate As String
End Class
<XmlRootAttribute([ElementName]:="Envelope", [Namespace]:="http://www.gesmes.org/xml/2002-08-01")>
Public Class Envelope
<XmlElement([ElementName]:="subject", [Namespace]:="http://www.gesmes.org/xml/2002-08-01")>
Public Property subject As String
<XmlElement([ElementName]:="Sender", [Namespace]:="http://www.gesmes.org/xml/2002-08-01")>
Public Property Sender As Sender
<XmlElement([ElementName]:="Cube", [Namespace]:="http://www.ecb.int/vocabulary/2002-08-01/eurofxref")>
Public Property Cube As Cube
<XmlAttribute([AttributeName]:="gesmes", [Namespace]:="http://www.w3.org/2000/xmlns/")>
Public Property Gesmes As String
<XmlAttribute([AttributeName]:="xmlns")>
Public Property Xmlns As String
End Class
Когда я беру эту структуру и сериализую ее обратно, используя следующую функцию
Public Function ToXML(ByVal struct As Envelope, ByVal t As Type) As String
Dim stringwriter = New System.IO.StringWriter()
Dim serializer = New XmlSerializer(t)
serializer.Serialize(stringwriter, struct)
Return stringwriter.ToString()
End Function
Удаляет все дочерние узлы.