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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with XML Reading

Status
Not open for further replies.

NervousRex

Programmer
Sep 4, 2003
66
0
0
US
I am new to XML and trying to do a simple read, currently i'm attempting to use XmlTextReader, but if you have a another suggestion that works I am not picky =)


Here is what I have, which doesn't work:


Code:
        Dim sr As StringReader = New StringReader(Me.hidSpellXML.Value)

        Dim textReader As XmlTextReader = New XmlTextReader(sr)
        While textReader.Read()
            ' If the node has value
            If textReader.HasValue Then
               Dim ctrl As Control = FindControl(textReader.Item(0))

                ' Move to fist element
                textReader.MoveToElement()

                CType(ctrl, TextBox).Text = textReader.Value.ToString()

            End If

        End While

my XML string looks like this currently:

<controlstocheck>
<control id="q1">
<text>spelling test</test>
<space> </space>
</control>
<control id="q8">
<text>more spelling test</test>
<space> </space>
</control>
</controlstocheck>


The XML has the corrected spelling from any text boxes on my form. I need to read in the id of the control, and then set the value of the control to the corrected spelling.

I had to use an attribute value for the control id, if I put it as an element the spellchecker reads it which I don't want.
 
I've currently got the following to read my XML file:
Code:
Dim oXmlDoc As New XmlDocument
        Try
            oXmlDoc.Load(sConfigFile) '= False Then
        Catch ex As Exception

            MsgBox("Failed to access ConfigFile due to: " & ex.Message)
            GetConfig = False
            Exit Function
        End Try
        
        sUsername = oXmlDoc.GetElementsByTagName("username").Item(0).InnerText
        sPassword = oXmlDoc.GetElementsByTagName("password").Item(0).InnerText
        sDatabase = oXmlDoc.GetElementsByTagName("database").Item(0).InnerText
        sBomCode = oXmlDoc.GetElementsByTagName("bomcode").Item(0).InnerText
        sDebug = oXmlDoc.GetElementsByTagName("debug").Item(0).InnerText
        sInclude = oXmlDoc.GetElementsByTagName("include").Item(0).InnerText
        sExclude = oXmlDoc.GetElementsByTagName("exclude").Item(0).InnerText

As you can probably see, this reads my file and assigns the elements inside the specified tags into variables. This might be of use to you if it means you can use the control id as a tag as well?



Cheers,
Dave

"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software." <-- Me

For all your testing needs: Forum1393
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top