I've got the following XML document that contains application settings:
I can get things at the end of a chain reasonably simply. For example, this code:Code:<?xml version="1.0" encoding="utf-8" ?> <Environment> <Live> <Database>LiveDB</Database> <Server>LiveServer</Server> <UserID>LiveID</UserID> <Password>LivePassword</Password> <DatabaseType>System.Data.SqlClient</DatabaseType> </Live> <UAT> <Database>UATDB</Database> <Server>UATServer</Server> <UserID>UATID</UserID> <Password>UATPassword</Password> <DatabaseType>System.Data.SqlClient</DatabaseType> </UAT> <Development> <Database>DevDB</Database> <Server>DevServer</Server> <UserID>DevID</UserID> <Password>DevPassword</Password> <DatabaseType>System.Data.SqlClient</DatabaseType> </Development> </Environment>
... will return "UATDB". Easy.Code:Dim xpathDoc As XPathDocument = New XPathDocument("C\SettingsDocument.xml") Dim xmlNav As XPathNavigator = xpathDoc.CreateNavigator() Dim xmlNI As XPathNodeIterator xmlNI = xmlNav.Select("/Environment/UAT/Database") While xmlNI.MoveNext() MessageBox.Show(xmlNI.Current.Value) End While
The problem is that I'd like to get hold of a list of the environments, i.e. Live, UAT and Development. I had imagined that using the above code but swapping out the lineforCode:xmlNI = xmlNav.Select("/Environment/UAT/Database")would do it, but it doesn't - it basically retuns a string of all the end values: "LiveDBLiveServerLiveIDLivePasswordSystem.Data.SqlClientUATDBUATServerUATIDUATPasswordSystem.Data.Sq lClientDevDBDevServerDevIDDevPasswordSystem.Data.SqlClient". Not helpful.Code:xmlNI = xmlNav.Select("/Environment")
So, does anyone know how I can get a list of the those environments out of that XML?
Much obliged.![]()




Reply With Quote