2016-05-29 17 views
0

以下のXMLファイルが含まれています。私は "日" の日付18/12/2015に "ParamValue" 属性の値を知りたいXMLファイルの属性値を検索VB.net

<?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" /> 

ので、 "ParamValues" 型ActiveTotalImport」と "SipValue" 時間1:15。その結果は0.5であるべきである。

これらは私はVB.net使用してリストボックスに試行コードである。

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がが18/12/2015〇時00分00秒の値を選択している、ListBox2が選択したActiveTotalImport値ListBox3は01:15の値を選択しています。したがって、結果は0.5値であるListBox4に追加されます。しかし、このコードは動作していない私が出て

答えて

0

てみた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 
+0

おかげでそれを解決する助けてください、あなたは非常に多くの – user38701

関連する問題