Announcement

Collapse
No announcement yet.

Replace numbers in an XML files

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replace numbers in an XML files

    Hi,
    I have an XML file with "numbers" that I need to replace them with other "numbers"

    e.g. the number 356 needs to be replaced with 4432

    I have a csv file for reference with all the old numbers and the new numbers that need to be replaced (few hundred of them... )

    one issue is that if you search for a number you might hit a GUID or something like that with the number in it

    e.g 23445-2345-2145-3455 and the number you looked for was 145...

    if you have a little script that can do ... I would appreciate it

  • #2
    Re: Replace numbers in an XML files

    Unless you give us more details, any script we give you would be a simple find and replace, which you already said you don't want. Maybe tell us the structure of the XML, are all the numbers at the same node of each branch?
    Gareth Howells

    BSc (Hons), MBCS, MCP, MCDST, ICCE

    Any advice is given in good faith and without warranty.

    Please give reputation points if somebody has helped you.

    "For by now I could have stretched out my hand and struck you and your people with a plague that would have wiped you off the Earth." (Exodus 9:15) - I could kill you with my thumb.

    "Everything that lives and moves will be food for you." (Genesis 9:3) - For every animal you don't eat, I'm going to eat three.

    Comment


    • #3
      Re: Replace numbers in an XML files

      Use a regular expression in a subroutine (in a batch or vbs script).

      As gforce already stated, we do need much more details.

      Are the numbers to search and replace in the text files (XML) be identified like,

      <space>4432<space> (where 4432 can be any number from the csv file)
      or,
      <begin of line>4432<space>
      or,
      <begin of line>4432<end of line>
      or,
      <space>4432<end of line>
      or,
      <some sign>4432<space>
      ect. ect.

      ?

      And can you show the structure of the values of the csv-file as well?


      \Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Replace numbers in an XML files

        Originally posted by XtaZee View Post
        if you search for a number you might hit a GUID or something like that with the number in it

        e.g 23445-2345-2145-3455 and the number you looked for was 145...
        The answer is, of course, a regular expression. The exact syntax depends on your environment. As a rule of thumb, you'd look for a word boundary, some digits and another a word boundary. Wrap within capturing parenthesis and replace with whatever you wish for.

        -vP

        Comment


        • #5
          Re: Replace numbers in an XML files

          Originally posted by Rems View Post
          Use a regular expression in a subroutine (in a batch or vbs script).

          As gforce already stated, we do need much more details.

          Are the numbers to search and replace in the text files (XML) be identified like,

          <space>4432<space> (where 4432 can be any number from the csv file)
          or,
          <begin of line>4432<space>
          or,
          <begin of line>4432<end of line>
          or,
          <space>4432<end of line>
          or,
          <some sign>4432<space>
          ect. ect.

          ?

          And can you show the structure of the values of the csv-file as well?


          \Rems

          the XML is something like this:


          &lt;Literal Value="2313" DataType="System.String" /&gt;
          <LiteralBind>294</LiteralBind>

          but also have this -- never change something like this line: <LiteralBind>2008-01-10T13:22:49.5620605+02:00</LiteralBind>


          the CSV file look like this:

          19,4635
          43,4470
          256,406
          257,407
          267,408
          294,398
          2313,5898

          replace needed for Value="2313" and <LiteralBind>294</LiteralBind>

          The numbers can range from 1 to 10,000
          Last edited by XtaZee; 6th January 2009, 11:05. Reason: added more info

          Comment

          Working...
          X