Update a specific XML node

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

    #1

    Update a specific XML node

    Hi,

    I have the following XML file :
    <?xml version='1.0' encoding='UTF-8'?>
    <Database>
    <ConnectionStri ng Type="PostgreSQ L v8.2.x">
    <DBName>c2st</DBName>
    <Host>127.0.0.1 </Host>
    <Port>5432</Port>
    <Username>use r</Username>
    <Password>pwd </Password>
    </ConnectionStrin g>
    <ConnectionStri ng Type="MySQL v4.x">
    <DBName>dbtes t</DBName>
    <Host>127.0.0.1 </Host>
    <Port>5432</Port>
    <Username>myuse r</Username>
    <Password>mypwd </Password>
    </ConnectionStrin g>
    </Database>

    How can i update only 1 particular node of this XML file without
    browsing the whole nodes ?

    for example, i would like to change <PortinnerXML value (5432) to 1258
    for MySQL v4.x connection string.

    All methods i've read till now are browsing the whole nodes and this i
    would like to avoid as much as possible.

    thanks a lot,

    Alain
  • Jon Skeet [C# MVP]

    #2
    Re: Update a specific XML node

    On Aug 13, 7:50 am, "Alain R." <noem...@nospam .comwrote:

    <snip>
    How can i update only 1 particular node of this XML file without
    browsing the whole nodes ?
    >
    for example, i would like to change <PortinnerXML value (5432) to 1258
    for MySQL v4.x connection string.
    >
    All methods i've read till now are browsing the whole nodes and this i
    would like to avoid as much as possible.
    What exactly do you mean by "browsing the whole nodes"? The easiest
    way is probably to use an XPath expression to find the element you
    want, and then update it. However, I don't know whether that would
    count as "browsing the whole nodes" in your view.

    If you want to update the file, you'll have to rewrite the whole thing
    though.

    Jon

    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Update a specific XML node

      On Aug 13, 10:07 am, "Alain R." <noem...@nospam .comwrote:
      I did that (see below) and it works well...i'm just scared when XMl file
      will be huge.
      So how big do you expect your files to be, and have you tested it with
      a file that large?

      It's better to have evidence under your belt than to be scared of
      something that may not be a problem.

      Jon

      Comment

      • Alain R.

        #4
        Re: Update a specific XML node

        for now XML is les than 1 kb as i just started to work on it.

        but i expect it will reach 600 kb.


        Jon Skeet [C# MVP] wrote:
        On Aug 13, 10:07 am, "Alain R." <noem...@nospam .comwrote:
        >I did that (see below) and it works well...i'm just scared when XMl file
        >will be huge.
        >
        So how big do you expect your files to be, and have you tested it with
        a file that large?
        >
        It's better to have evidence under your belt than to be scared of
        something that may not be a problem.
        >
        Jon
        >

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Update a specific XML node

          On Aug 13, 10:35 am, "Alain R." <noem...@nospam .comwrote:
          for now XML is les than 1 kb as i just started to work on it.
          >
          but i expect it will reach 600 kb.
          600K is still relatively small. By the time it's loaded into memory it
          will be significantly bigger of course, but unless you're loading and
          saving thousands of these on a very frequent basis, I wouldn't expect
          it to be a problem.

          To be confident, however, you should see if you can create or find a
          file of that size, and see how it performs.

          Jon

          Comment

          • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

            #6
            Re: Update a specific XML node

            Alain R. wrote:
            for now XML is les than 1 kb as i just started to work on it.
            >
            but i expect it will reach 600 kb.
            I think DOM in memory size typical is about 5 times on disk size.

            In that case it is just 3 MB.

            Arne

            Comment

            • Jon Skeet [C# MVP]

              #7
              Re: Update a specific XML node

              Arne Vajhøj <arne@vajhoej.d kwrote:
              It is not a 100 times.
              So have you found the worst cases and measured it?
              No - I don't really see any point in it.
              If the worst case is known to be okay for the OP's situation, then
              there's no need to try a representative file. Otherwise, however, it
              *is* a good idea to try one.
              You're assuming that *all* of the XML is like the sample posted. 600K
              just of database connections is an awful lot - maybe there'll be other
              data...
              Sure.

              But almost by definition I would expect that to be more close
              to average than the worst case possible to create.
              True - but without knowing how bad the worst case is, that's not much
              comfort.

              --
              Jon Skeet - <skeet@pobox.co m>
              http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
              If replying to the group, please do not mail me too

              Comment

              • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

                #8
                Re: Update a specific XML node

                Jon Skeet [C# MVP] wrote:
                Arne Vajhøj <arne@vajhoej.d kwrote:
                >>You're assuming that *all* of the XML is like the sample posted. 600K
                >>just of database connections is an awful lot - maybe there'll be other
                >>data...
                >Sure.
                >>
                >But almost by definition I would expect that to be more close
                >to average than the worst case possible to create.
                >
                True - but without knowing how bad the worst case is, that's not much
                comfort.
                Why not. If real XML files are <10 it does not matter much if is
                possible to construct an example with 17 or 27.

                Arne

                Comment

                • Jon Skeet [C# MVP]

                  #9
                  Re: Update a specific XML node

                  Arne Vajhøj <arne@vajhoej.d kwrote:
                  Jon Skeet [C# MVP] wrote:
                  Arne Vajhøj <arne@vajhoej.d kwrote:
                  >You're assuming that *all* of the XML is like the sample posted. 600K
                  >just of database connections is an awful lot - maybe there'll be other
                  >data...
                  Sure.
                  >
                  But almost by definition I would expect that to be more close
                  to average than the worst case possible to create.
                  True - but without knowing how bad the worst case is, that's not much
                  comfort.
                  Why not. If real XML files are <10 it does not matter much if is
                  possible to construct an example with 17 or 27.
                  But the point is that we didn't know what the genuine XML file would be
                  like. We hadn't experimented to find out *either* what it would be like
                  with real data *or* what a worst case would be. Using samples of other
                  XML files which may or may not be anything like the real one isn't
                  enough, IMO.

                  --
                  Jon Skeet - <skeet@pobox.co m>
                  http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                  If replying to the group, please do not mail me too

                  Comment

                  Working...