Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning line from XML file...

Status
Not open for further replies.

lidds

Programmer
Jun 9, 2005
72
GB
I have a file called setting.xml which contains the following:

Code:
<?xml version="1.0" encoding="utf-8"?>
<settings 

licenseServiceType="1"

protectedStorageFile="%AppDomainAppPath%App_Data\storage.psf"
addressSigned="tgAAAIv1/CTaEM0BkLI9HW0ozQEZAGh0dHA6Ly8xMC4xMjguNTQuNDk6ODA5MS96FnzeHrzBS3YydgZ/nSOa8zEGLKNhas0PomOdV/JBhBP9HLq09G6MUb6uwoJ4ogQ="  
customerDeploymentLicenseCode="dgAAAJEL0iTaEM0BkLI9HW00"

>

</settings>

What I am trying to do is return the information for the "customerDeploymentLicenseCode" line e.g. dgAAAJEL0iTaEM0BkLI9HW00

I have done the following code, but for some reason it is not matching/finding that line and therefore returns nothing. I can't seem to figure out why not, is it possible for someon to point out my mistake?

Code:
    Public Function GetServerLicenseCode() As String 
	Dim settingsFilePath As String = GetRealFilePath("%AppDomainAppPath%App_Data\settings.xml")
        Dim objFileName As FileStream = New FileStream(settingsFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
        Dim objFileRead As StreamReader = New StreamReader(objFileName)
        Dim customerLicCode As String = ""
        Do While (objFileRead.Peek() > -1)
            If objFileRead.ReadLine().IndexOf("customerDeploymentLicenseCode") <> -1 Then
                '    customerLicCode = objFileRead.ReadLine().Replace("customerDeploymentLicenseCode=", "")
                customerLicCode = objFileRead.ReadLine()
                Exit Do
            End If
        Loop

        Return customerLicCode
    End Function

Thanks

Simon
 
Since this is an XML file, use the XML objects in .NET to read it:


Dim XMLDoc As XmlDocument

Dim SettingsList As XmlNodeList

Dim SettingsNode As XmlNode

Dim customerLicCode As String = ""

XMLDoc = New XmlDocument

XMLDoc.Load("%AppDomainAppPath%App_Data\settings.xml")

SettingsList = XMLDoc.SelectNodes("/settings")

SettingsNode = SettingsList(0) 'I'm not too sure about this index, you might need to change this line a bit

customerLicCode = SettingsNode.Attributes("customerDeploymentLicenseCode").Value



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top