Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|