0

I have a following details included xml file.

<?xml version="1.0" encoding="utf-8"?>
<LoadSurveyValues>
  <LoadSurvey timeStamp="18/12/2015 11:13:02" saveMode="SnapShot">
    <Date Date="18/12/2015 00:00:00">
      <ParamValues Type="ActiveTotalImport" Unit="kWh">
        <SipValues Time="00:15" ParamValue="0" />
        <SipValues Time="00:30" ParamValue="0" />
        <SipValues Time="00:45" ParamValue="0" />
        <SipValues Time="01:00" ParamValue="0" />
        <SipValues Time="01:15" ParamValue="0.5" />
        <SipValues Time="01:30" ParamValue="0.1" />
        <SipValues Time="01:45" ParamValue="0" />
        <SipValues Time="02:00" ParamValue="0" />
        <SipValues Time="02:15" ParamValue="0" />
        <SipValues Time="02:30" ParamValue="0" />

and so on

I want to find out "ParamValue" attribute value in "Date" date 18/12/2015, "ParamValues" type ActiveTotalImport" and "SipValue" time 01:15. That result should be 0.5.

These are codes I tried in VB.net using listboxes.

  Dim xr As XmlReader = XmlReader.Create("meter 01.xml")
  If ListBox1.SelectedIndex >= 0 Then
        If ListBox2.SelectedIndex >= 0 Then
            If ListBox3.SelectedIndex >= 0 Then

                If xr.NodeType = XmlNodeType.Element And xr = ListBox1.SelectedIndex And xr = ListBox2.SelectedIndex And xr = ListBox3.SelectedIndex Then

                    ListBox4.Items.Add(xr.GetAttribute(1))

                End If
            End If
        End If
    End If

ListBox1 has selected 18/12/2015 00:00:00 value, ListBox2 has selected ActiveTotalImport value and ListBox3 has selected 01:15 value. Therefore the result is adding to the ListBox4 which is 0.5 value. But this code is not working please help me solve it out

1 Answer 1

0

Try xml linq

Imports System.Xml
Imports System.Xml.Linq
Module Module1
    Const FILENAME As String = "c:\temp\test.xml"
    Sub Main()
        Dim doc As XDocument = XDocument.Load(FILENAME)

        Dim survey As XElement = doc.Descendants("LoadSurvey").Where(Function(x) x.Attribute("timeStamp").Value = "18/12/2015 11:13:02").FirstOrDefault()
        Dim ParamValue As String = survey.Descendants("SipValues").Where(Function(x) x.Attribute("Time").Value = "01:15").Select(Function(y) y.Attribute("ParamValue")).FirstOrDefault()
    End Sub

End Module
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.