B
Budinsky
Guest
Need to read an xml file from a program that may vary depending on the user options, mainly with grouping data.
List should contain two elements EnvConfig/Name and DongleConfigs/Name.
The list will be used to populate two drop down menus.
EnvConfigs list = Standard, NSW, SA, QLD, WA
DongleConfigs list = General, Special, Stand-alone Dongle
<Configurations>
<Group>
<Name>EnvConfigs</Name>
<Group>
<EnvConfig>
<Name>Standard</Name>
</EnvConfig>
</Group>
<Group>
<Name>Clients</Name>
<EnvConfig>
<Name>NSW</Name>
</EnvConfig>
<EnvConfig>
<Name>SA</Name>
</EnvConfig>
<EnvConfig>
<Name>QLD</Name>
</EnvConfig>
<EnvConfig>
<Name>WA</Name>
</EnvConfig>
</Group>
</Group>
<Group>
<Name>DongleConfigs</Name>
<DongleConfig>
<Name>General</Name>
</DongleConfig>
<DongleConfig>
<Name>Special</Name>
</DongleConfig>
<DongleConfig>
<Name>Stand-alone Dongle</Name>
</DongleConfig>
</Group>
<Group>
<Name>WorkspaceConfigs</Name>
</Group>
</Configurations>
This is my attempt but I'm sure there's a better way.
Private Sub ReadXml()
Dim doc As XDocument = XDocument.Load(txtConfig.Text)
Dim XMLConfig As IEnumerable(Of XElement) = doc.Root.Elements("Group")
Dim envConfig As String
Dim dongleConfig As String
For Each xel As XElement In XMLConfig
envConfig = xel.Element("EnvConfig").Element("Name").Value
dongleConfig = xel.Element("DongleConfig").Element("Name").Value
MessageBox.Show(envConfig)
MessageBox.Show(dongleConfig)
Next
End Sub
Continue reading...
List should contain two elements EnvConfig/Name and DongleConfigs/Name.
The list will be used to populate two drop down menus.
EnvConfigs list = Standard, NSW, SA, QLD, WA
DongleConfigs list = General, Special, Stand-alone Dongle
<Configurations>
<Group>
<Name>EnvConfigs</Name>
<Group>
<EnvConfig>
<Name>Standard</Name>
</EnvConfig>
</Group>
<Group>
<Name>Clients</Name>
<EnvConfig>
<Name>NSW</Name>
</EnvConfig>
<EnvConfig>
<Name>SA</Name>
</EnvConfig>
<EnvConfig>
<Name>QLD</Name>
</EnvConfig>
<EnvConfig>
<Name>WA</Name>
</EnvConfig>
</Group>
</Group>
<Group>
<Name>DongleConfigs</Name>
<DongleConfig>
<Name>General</Name>
</DongleConfig>
<DongleConfig>
<Name>Special</Name>
</DongleConfig>
<DongleConfig>
<Name>Stand-alone Dongle</Name>
</DongleConfig>
</Group>
<Group>
<Name>WorkspaceConfigs</Name>
</Group>
</Configurations>
This is my attempt but I'm sure there's a better way.
Private Sub ReadXml()
Dim doc As XDocument = XDocument.Load(txtConfig.Text)
Dim XMLConfig As IEnumerable(Of XElement) = doc.Root.Elements("Group")
Dim envConfig As String
Dim dongleConfig As String
For Each xel As XElement In XMLConfig
envConfig = xel.Element("EnvConfig").Element("Name").Value
dongleConfig = xel.Element("DongleConfig").Element("Name").Value
MessageBox.Show(envConfig)
MessageBox.Show(dongleConfig)
Next
End Sub
Continue reading...