Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Need some help with xml files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36694
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need some help with xml files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Need some help with xml files - 8/3/2006 12:57:16 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi All,
I did a search regarding editing a value in a text file and i want to impliment it on an xml file.
1.  Is it possible?
2.  I dont know much vb i usually take some scripts from here and change them.

I need the script to open the xml file, search for a string and change the value.
the file contains a line that looks like this:

"agent endpoint="tcp://172.16.100.50:5005" unique.id="1A59F745-032B-4851-BA71-5D1FA2A8A61D"
 
i need to replace the ip to a new ip.  To enter an echo that request for the new ip i know how to do.
How do i create a script that will search for a string in the xml file and once it finds the string replace the value.
Once i will know how to do it i will be able to continue on my own.

Thanks for the support.

buff
 
 
Post #: 1
 
 RE: Need some help with xml files - 8/3/2006 1:27:31 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
PLease post a snippet of the actual XML.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to buffi)
 
 
Post #: 2
 
 RE: Need some help with xml files - 8/3/2006 2:10:43 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
sorry for the dumb question but was is a snippet????

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Need some help with xml files - 8/3/2006 2:12:25 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Some little piece of the code. Enough so that we can get an idea of the structure of your XML file.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to buffi)
 
 
Post #: 4
 
 RE: Need some help with xml files - 8/3/2006 2:16:42 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
This is a file called vvs.config file which i also need to edit:


      

And this is one of the xml files:


      


Thanks for the help
buff
[/size]

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Need some help with xml files - 8/3/2006 2:43:50 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi buffi,

While hierarchically structured data (xml, html, ...) should in principle treated as such,
sometimes you can get fast results by treating such data as a fancy kind of string.
So I'm not sure, whether this 'proof of concept' code


      

will be useful for your problem. Be aware, such brutal methods can mangle your data.

Good luck.

(in reply to buffi)
 
 
Post #: 6
 
 RE: Need some help with xml files - 8/3/2006 2:50:30 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
I don't believe the first snippet is valid XML (no root node for one thing). In that case you need to simply treat the file as a text file. Read it in, process each line to see if it has the information that you need to change, change it if it does, write it all back out. You can find several code examples by searching for terms like "FileSystemObject" and "Replace".

The second file does appear to be valid XML minus the XML header tag. In it's case you could use the XML DOM to make changes (search for "XMLDOM").

Either way, when you run into problems, post back here with a description of your problem and the code that you are running and we can help you out.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to buffi)
 
 
Post #: 7
 
 RE: Need some help with xml files - 8/3/2006 2:53:03 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi There,
Thanks for the help.  I will have a look on it once i am home :)
I am currently in my car writing this :P

Thanks again

buff

(in reply to ehvbs)
 
 
Post #: 8
 
 RE: Need some help with xml files - 8/23/2006 1:30:16 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
I tried to work with this but it changed the entire file to just the new id.
I need to change the IP and not the ID.

The reason for the script is that if the IP on the server is changed then you can run this script and it will change it on a couple of xml files.
When i set the parameter to change the ip the result i get is a xml file with only the ip i changed.  The script deletes the rest of the content of the xml file.

Any suggestions?

Regards,
buffi

(in reply to buffi)
 
 
Post #: 9
 
 RE: Need some help with xml files - 8/23/2006 1:54:46 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
Can't really help you without seeing your code and a sample of your XML.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to buffi)
 
 
Post #: 10
 
 RE: Need some help with xml files - 8/23/2006 5:04:33 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
hey mate
i have posted on top the xml file :)

here is it again.  - it is a short xml file for a certain configuration of a software:
[xml file]
<Computer version="8" compid="200" computername="LAB" siteguid="C2F252BF-B6AF-4F15-968C-A6AD631A29FE" mac="000D6065610C" ip="172.16.100.50"><Service type="311" status="stopped"><Name>CCTVware_ArchServer</Name><Description>CCTVware ArchiveServer</Description><Port>1422</Port></Service><Service type="303" status="running"><Name>CCTVware_ComServer</Name><Description>CCTVware ComServer</Description><Port>1421</Port></Service><Service type="310" status="stopped"><Name>CCTVware_MatrixServer</Name><Description>CCTVware_MatrixServer</Description><Port>1435</Port></Service><Service type="317" status="stopped"><Name>CCTVware_PlaybackServer</Name><Description>CCTVware PlaybackServer</Description><Port>1439</Port></Service><ips><ip>172.16.100.50</ip></ips></Computer>

I need a scrip that will change all the ip addresses (172.16.100.50) with a new one that i will put in a msgbox.
Also this ip might be different so i rather have something that will search for this ip=" " and for this <ip>.
If it is easier to do it in text file the scrip can first change the file from configuration.xml to configuration.txt - then change the ip to the new ip and then rename the file again to configuration.xml.


thanks again
buff

< Message edited by buffi -- 8/23/2006 5:07:40 AM >

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: Need some help with xml files - 8/23/2006 6:25:25 AM   
  ebgreen


Posts: 5246
Score: 31
Joined: 7/12/2005
Status: offline
So what changes have you made to the proof of concept code that ehvbs provided to try to get it to work for your specific situation?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to buffi)
 
 
Post #: 12
 
 RE: Need some help with xml files - 8/23/2006 7:44:31 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi buffi,

I'm afraid my 'proof of concept' code didn't show clearly that the text
it worked with was just

    sText   = "unique.id=""" + sOldId + """"

that is
   
    unique.id="1A59F745-032B-4851-BA71-5D1FA2A8A61D"

Let's assume the xml (saved as tidy_xmlbyforce.xml" looks like this:


      

Then this code:


      

should change the two Ips. You'll have to consider carefully, whether the strategy
"just replace all occurences of the first ip found with the ip entered by the user"
does really solve your problem.

Good luck!

(in reply to ebgreen)
 
 
Post #: 13
 
 RE: Need some help with xml files - 8/23/2006 4:58:02 PM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hey ehvbs,
 
Thanks alot.  I will check it :)
 

Woot :))  IT works like a charm :P

Thanks alot mate i really apreciate it :)

< Message edited by buffi -- 8/23/2006 5:18:29 PM >

(in reply to ehvbs)
 
 
Post #: 14
 
 RE: Need some help with xml files - 8/23/2006 11:09:13 PM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hey i also have  another file that i need to change the ip in although this one is little different.  On the other ones it worked like a charm:
This is the content of the other file:


      
I need to change the tcp:\\ ip.

I tried to edit the script you gave me with the other one but i get lots of errors :(

(in reply to buffi)
 
 
Post #: 15
 
 RE: Need some help with xml files - 8/25/2006 7:20:15 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi buffi,

just change the oRE.Pattern

   oRE.Pattern = "ip=""(\d+\.\d+\.\d+\.\d+)"""

to

   oRE.Pattern = "endpoint=""tcp://(\d+\.\d+\.\d+\.\d+:\d+)"""

and read about RegExps in the VBScript Docs (or some other tutorial).

(in reply to buffi)
 
 
Post #: 16
 
 RE: Need some help with xml files - 8/25/2006 7:31:11 AM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi All,

I did a search regarding editing a value in a text file and i want to impliment
it on an vbs file.

1.  Is it possible?
2.  I dont know much vb i usually take some scripts from here and change them.
    (But I would study the delivered scripts, look up the used concepts in
     the Docs - I want to understand what I use)

I need the script to open the vbs file, search for a string and change the value.
the file contains a line that looks like this:

  oRE.Pattern = <Some gibberish>
 
i need to replace the gibberish to a new gibberish.  To enter an echo that request
for the new gibberish i know how to do.
How do i create a script that will search for a gibberish in the vbs file and
once it finds the string replace the value.

Once i will know how to do it i will be able to continue on my own.

Thanks for the support.

ehvbs
 

(in reply to ehvbs)
 
 
Post #: 17
 
 RE: Need some help with xml files - 8/26/2006 3:27:41 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
HI ehvbs

thanks i will check it out

(in reply to ehvbs)
 
 
Post #: 18
 
 RE: Need some help with xml files - 8/27/2006 1:32:09 AM   
  buffi

 

Posts: 87
Score: 0
Joined: 3/28/2005
From:
Status: offline
Hi evbs,
i have changed what you have told me but now i get an error (line 12 char 4)

"  sOldIp      = oRE.Execute( sText )( 0 ).SubMatches( 0 )"

Any idea why?

Thanks,

p.s  you told me to read something - is this concerning this matter?

thanks,
buff

(in reply to buffi)
 
 
Post #: 19
 
 RE: Need some help with xml files - 8/27/2006 9:56:21 PM   
  ehvbs

 

Posts: 2222
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi buffi,

while we wait for the answer of this evbs guy to your last question, I'll tell
you about the communication I had with someone called bffi, who had exactly the
same problem as you:

  bffi: Hi ehvbs,
      I used your proof of concept code with the pattern:

           oRE.Pattern = "ip=""(\d+\.\d+\.\d+\.\d+)"""

      on a file containing

           <Computer version="8" compid="200" computername="LAB"
                     siteguid="C2F252BF-B6AF-4F15-968C-A6AD631A29FE"
                     mac="000D6065610C" ip="172.16.100.52"
           >
           ...
            <ips>
             <ip>172.16.100.52</ip>
            </ips>
           ...

      successfully, but when I changed the pattern to

           oRE.Pattern = "endpoint=""tcp://(\d+\.\d+\.\d+\.\d+:\d+)"""

      the script failed on the

           sOldIp      = oRE.Execute( sText )( 0 ).SubMatches( 0 )

      line with the error message:

           Ungültiger Prozeduraufruf oder ungültiges Argument

      Now my questions:

      (1) Do you think I should have used the script with the new pattern
          on the other file containing:
          
           <?xml version="1.0"?>
            <agent endpoint="tcp://173.17.101.52:5006" unique.id="1A59F745-032B-4851-BA71-5D1FA2A8A61D">
            ...
             <directory>
              <endpoint destination="tcp://173.17.101.52:5006" />
             </directory>
           ...

      (2) As I assumed that you wouldn't point me to some documentation
          completely unrelated to the problem at hand, I studied the topic
          "Introduction to Regular Expressions (Scripting)" in the VBScript
          Docs. My, that's complicated stuff! But based on my knowledge of the
          Instr() function, I gather that RegExps are just a more powerful
          way to seek in strings. My code using Instr() usually looks like
          this:

             nPos = Instr( "haystackwithneedle", "needle" )
             If 0 < nPos Then
                handle found
             Else
                handle found
             End If

          After reading about Regexp.Execute() and Regexp.Test() I think that your
          code should be improved like this:

             If oRE.Test( sText ) Then
                sOldIp      = oRE.Execute( sText )( 0 ).SubMatches( 0 )
                ...
             Else
                WScript.Echo "no match for", oRE.Pattern
             End If

          That way the script won't crash if used against files not containing
          the pattern searched for. Am I right?

      (3) Now I see that there is more work waiting if I want just one script that
          handles three or more different types of .xml files. I need a way to
          associate .xml files with suitable oRE.Patterns or some method to
          check a list of patterns against the file loaded. Are you willing
          to help me with this problem, if I provide some information concerning
          to intended use of the script?

  ehvbs: Hi bffi,

       The answers to your three questions: yes, yes, yes.
      
Perhaps this will solve your problem to - just in case evbs won't answer.

ehvbs
 

(in reply to buffi)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Need some help with xml files Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts