locked
How to read this XML element? RRS feed

  • Question

  • User-1668014665 posted
    <docs frequency="daily">
            <dataset_code>EXR</dataset_code>
            <dataset_name>Exchange Rates</dataset_name>
            <indexed_at>2020-08-08T09:19:15.366Z</indexed_at>
            <provider_code>ECB</provider_code>
            <series_code>D.AUD.EUR.SP00.A</series_code>
            <series_name>Daily – Australian dollar – Euro – Spot – Average</series_name>
            <dimensions>
              <CURRENCY>AUD</CURRENCY>
              <CURRENCY_DENOM>EUR</CURRENCY_DENOM>
              <EXR_SUFFIX>A</EXR_SUFFIX>
              <EXR_TYPE>SP00</EXR_TYPE>
              <FREQ>D</FREQ>
            </dimensions>
    </docs>
                Dim nPeriodType As String = "None"
                Dim dt1 As New DataTable
                Dim ds1 As New DataSet
                Dim xml1 As XmlNode = JsonConvert.DeserializeXmlNode("{records:{record:" & History1 & "}}")
                Dim xmldoc1 As XmlDocument = New XmlDocument()
                xmldoc1.LoadXml(xml1.InnerXml)
                xmlReader1 = New XmlNodeReader(xml1)
                ds1.ReadXml(xmlReader1)
    
    
                If ds1.Tables("docs") IsNot Nothing Then
                    dt1 = ds1.Tables("docs")
    
                    If dt1.Rows.Count = 0 Then
                        res = "Error1: No records in XML source file."
                        Return "DataID " & DataSubID.ToString & ", " & Symbol & ", " & res
                    End If
                Else
                    Throw New Exception(Symbol & ", DBNomics Server Error(Docs) not found.")
                End If
    
    
       

    QUESTION : How can I read the contents of  attribute or element frequency in the first line <docs frequency="daily">??

    Out put wanted is 'Daily'.

    Using dt1 DataTable or other means?

    Any ideas?

    Sunday, August 9, 2020 9:54 PM

Answers

  • User-943250815 posted

    Considering you have XML as String

    Dim myXMLStr as string ' store xml string
    Dim myXML As New System.Xml.XmlDocument
    myXML.LoadXML(myXMLStr)
    Dim myAttrVal as string = myXML.DocumentElement.Attributes("frequency").Value

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 10, 2020 1:26 PM