I've asked a question some time ago, and got help, but the requirements have changed and i need more :)
The original question:
Quote:
I dont code that often, and i forget. So instead of hours of googling for something i dont know what is called, i ask a question here with the experts :)
I want to get specific values out of this XML:
="1.0"="UTF-16"
<ROOT>
<TREE Version="01.00" Company="OTHER" StationNr="0111">
<Device Type="1">
<Property Type="1">111</Property>
<Device Type="2" Number="1">
<Property Type="34">INT</Property>
<Device Type="3">
<Device Type="4" Number="1">
<Property Type="56">192.168.242.192</Property>
<Device Type="29">
<Property Type="71">11016938</Property>
</Device>
</Device>
<Device Type="4" Number="2">
<Property Type="56">192.168.242.193</Property>
<Device Type="29">
<Property Type="71">11016933</Property>
</Device>
</Device>
</Device>
</Device>
</Device>
</TREE>
</ROOT>
Heres what i am looking for:
I want to look for the property attribute 56 and get the value of 192.168.242.192 when reading.
I also want to loop through property type 2, to find all device type 4.
I also would like to get the value Property Type="71" of this one.
I have a few examples from my past coding, but no XML i have used in the past, looks like this one.
Any idea what to search for?
This was the help i got, and it worked like a charm
Dim xdoc As XDocument = XDocument.Load("FullFileName.xml")
Dim deviceTypes2find As String() = {"1", "4"}
Dim propTypes2find As String() = {"56", "71"}
Dim result = xdoc.Descendants("Property"). _
Where(Function(x) propTypes2find.Any(Function(a) x.Attribute("Type").Value=a) AndAlso _
deviceTypes2find.Any(Function(y) x.Parent.Attribute("Type").Value = y)). _
Select(Function(x) Tuple.Create(x.Parent.Attribute("Type").Value, x.Attribute("Type").Value, x.Value)). _
ToList()
Console.WriteLine(String.Format("{0}{1}{2}{1}{3}", "DeviceTypeId", Microsoft.VisualBasic.vbTab, "PropertyTypeId", "Value"))
For Each t As Tuple(Of String, String, String) In result
Console.WriteLine(String.Format("{0}{1}{2}{1}{3}", t.Item1, Microsoft.VisualBasic.vbTab, t.Item2, t.Item3))
Next
But now i need more:
Below
<device type="1">
i have several
<device type="4" number="1">
The following, usually, has an increasing value in "Number", this is the value i need.
Can i get this value, using the solution provided in the past?
What I have tried:
I have tried modifying the code, but without luck..