modify value into XML file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maileen

    modify value into XML file

    Hi,

    I've asked yesterday if someone already modify data into XML file using
    VB.NET.

    In fact, my XML file is like that.

    ....
    <DB>
    <DB_Loc>
    mytext
    </DB_Loc>
    </DB>
    <SETTINGS>
    ....
    </SETTINGS>
    ....

    I would like to modify my text "mytext" and replace it by some other value.

    How can I do this ?
    thanks,
    Maileen
  • Nigel Armstrong

    #2
    RE: modify value into XML file

    Hi Maileen

    Without testing...

    Dim d As New System.Xml.XmlD ocument
    d.LoadXml("<DB> <DB_Loc>mytex t</DB_Loc></DB>")
    Dim n As System.Xml.XmlN ode = d.SelectSingleN ode("//DB/DB_Loc") ' your
    example implies that DB is not the root element...
    n.InnerText = "A new value"
    d.Save("C:\test .xml")

    HTH

    Nigel Armstrong

    "Maileen" wrote:
    [color=blue]
    > Hi,
    >
    > I've asked yesterday if someone already modify data into XML file using
    > VB.NET.
    >
    > In fact, my XML file is like that.
    >
    > ....
    > <DB>
    > <DB_Loc>
    > mytext
    > </DB_Loc>
    > </DB>
    > <SETTINGS>
    > ....
    > </SETTINGS>
    > ....
    >
    > I would like to modify my text "mytext" and replace it by some other value.
    >
    > How can I do this ?
    > thanks,
    > Maileen
    >[/color]

    Comment

    • Maileen

      #3
      Re: modify value into XML file

      but in your example, i don't load the XML source file
      before...everyt hing is done in memory.

      before to modify data of node, I want to open the XML file and modify
      directly to XML file the value.

      Maileen

      Nigel Armstrong wrote:[color=blue]
      > Hi Maileen
      >
      > Without testing...
      >
      > Dim d As New System.Xml.XmlD ocument
      > d.LoadXml("<DB> <DB_Loc>mytex t</DB_Loc></DB>")
      > Dim n As System.Xml.XmlN ode = d.SelectSingleN ode("//DB/DB_Loc") ' your
      > example implies that DB is not the root element...
      > n.InnerText = "A new value"
      > d.Save("C:\test .xml")
      >
      > HTH
      >
      > Nigel Armstrong
      >
      > "Maileen" wrote:
      >
      >[color=green]
      >>Hi,
      >>
      >>I've asked yesterday if someone already modify data into XML file using
      >>VB.NET.
      >>
      >>In fact, my XML file is like that.
      >>
      >>....
      >><DB>
      >> <DB_Loc>
      >> mytext
      >> </DB_Loc>
      >></DB>
      >><SETTINGS>
      >>....
      >></SETTINGS>
      >>....
      >>
      >>I would like to modify my text "mytext" and replace it by some other value.
      >>
      >>How can I do this ?
      >>thanks,
      >>Maileen
      >>[/color][/color]

      Comment

      • Maileen

        #4
        Re: modify value into XML file

        I've discovered where was the mistake.
        I don't know why, but VB wrote the changes into another folder than
        where it should be done, so never my xml file was modified even if
        folder and file variable where correct.

        so code is good.
        Maileen

        Nigel Armstrong wrote:[color=blue]
        > Hi Maileen
        >
        > Without testing...
        >
        > Dim d As New System.Xml.XmlD ocument
        > d.LoadXml("<DB> <DB_Loc>mytex t</DB_Loc></DB>")
        > Dim n As System.Xml.XmlN ode = d.SelectSingleN ode("//DB/DB_Loc") ' your
        > example implies that DB is not the root element...
        > n.InnerText = "A new value"
        > d.Save("C:\test .xml")
        >
        > HTH
        >
        > Nigel Armstrong
        >
        > "Maileen" wrote:
        >
        >[color=green]
        >>Hi,
        >>
        >>I've asked yesterday if someone already modify data into XML file using
        >>VB.NET.
        >>
        >>In fact, my XML file is like that.
        >>
        >>....
        >><DB>
        >> <DB_Loc>
        >> mytext
        >> </DB_Loc>
        >></DB>
        >><SETTINGS>
        >>....
        >></SETTINGS>
        >>....
        >>
        >>I would like to modify my text "mytext" and replace it by some other value.
        >>
        >>How can I do this ?
        >>thanks,
        >>Maileen
        >>[/color][/color]

        Comment

        Working...