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

Replacing a XML file Value .net CF

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
I have the code below testing and XML file to see if the userid is "0000". If so I want to replace the value "0000" with one submitted. I cant figure it out. I know (or think I do ) that I need a xmltextwriter but I cant get it to work.

Code:
 Private Sub xml_read()

        Dim userid As String
        Dim writer As XmlTextWriter = Nothing
        Dim asm As [Assembly] = [Assembly].GetExecutingAssembly()
        Dim appPath As String = System.IO.Path.GetDirectoryName(asm.GetName().CodeBase)

        Dim reader As XmlTextReader = Nothing
        Try
            reader = New XmlTextReader(appPath & "\userid.xml")

            While reader.Read()

                If reader.Name = "stuid" Then
                    reader.Read()
                    userid = (reader.ReadString())
                    
                   If userid = "0000" Then

' ** enter new value here

                    End If

                End If

            End While

            Me.TextBox1.Text = userid

        Finally
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try

    End Sub

The file im using has this in it. I want to replcae the "0000"'s with another number like"6872"


Code:
<?xml version="1.0" encoding="utf-8" ?> 
<student>
  <stuid>0000</stuid>
  <dteassgd>2005-08-24</dteassgd> 
</student>

Thanks

Dan
 
Load it into XmlDocument object, then use selectsinglenode(student/stuid[. = '0000']) to get the required node. Alter the value with node.value = new value. Then save xmldoc.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top