#169468 - 2006-10-16 10:59 PM
XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Hi Guys, I'm not sure what happened to my last post, but it didn't seem to post early this morning, so I am going to try this again.
I need to be able to use the KIX script to rewrite what is in the following tag:
C:\windows\folderName\
and become (replace with):
G:\NEWfolderName\
Does anyone have any ideas to help me out?
Thanks!
Faithful
|
Top
|
|
|
|
#169470 - 2006-10-17 12:40 AM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
You can't just replace it like you could with an ini file?
[CODE]<Receipt value='YES'>G:\Windows\NewFolder\</Receipt>[/CODE]
It's a rather large file, and I just want to modify the one entry. Any other ideas or is that they only way?
Thanks,
Faithful
Edited by Faithfulman (2006-10-17 12:41 AM)
|
Top
|
|
|
|
#169471 - 2006-10-17 01:31 AM
Re: XML - writing to existing file
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Faithfulman, what Jooel is saying is that a .xml file is like a .txt file and can be opened and then read each line looking for the appropriate text then once you find it write the line back as you desire then close the file and your done.
|
Top
|
|
|
|
#169472 - 2006-10-17 01:59 AM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
I really have not done too much of this. Can someone give me some example or some guidance?
Thanks,
Faithful
|
Top
|
|
|
|
#169473 - 2006-10-17 09:30 AM
Re: XML - writing to existing file
|
Mart
KiX Supporter
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Something like this. Not tested but it looks like it should work just fine.
Code:
Break on ; $sourcefile = "c:\sourcexmlfile.xml" $newfile = "c:\newxmlfile.xml" ; $rc = Open (1, $sourcefile, 2) $rc = Open (2, $newfile, 5) ; $line = ReadLine (1) If InStr ($line, "C:\windows\folderName\") $line = Split($line, "C:\windows\folderName\") $line = Join ($line, "G:\NEWfolderName\") $rc = WriteLine (2, $line + @CRLF) Else $rc = WriteLine (2, $line + @CRLF) EndIf ; $rc = Close(1) $rc = Close(2)
[edit] Hmmmm..... There could be an issue with paths that have C:\windows\folderName\ in it and should not be changed. Depends on your situation and if all the lines that have C:\windows\folderName\ in it should be changed. [/edit]
Edited by Mart (2006-10-17 09:42 AM)
|
Top
|
|
|
|
#169474 - 2006-10-18 01:39 AM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Code didn't take so I have posted the issue at hand down below:
Edited by Faithfulman (2006-10-18 06:53 AM)
|
Top
|
|
|
|
#169476 - 2006-10-18 02:00 AM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Okay, from this
Quote:
<Receipt> <test>This is too cool</test> </Receipt>
to
Quote:
<Receipt> <test>This is too cool</test> </Receipt>
Using This
Code:
Break on ; $sourcefile = "c:\XMLfile.xml" $newfile = "c:\newXMLfile.xml" ; $rc = Open (1, $sourcefile, 2) $rc = Open (2, $newfile, 5) ; $line = ReadLine (1) If InStr ($line, "This is too cool") $line = Split($line, "This is too cool") $line = Join ($line, "Dude") $rc = WriteLine (2, $line + @CRLF) Else $rc = WriteLine (2, $line + @CRLF) EndIf ; $rc = Close(1) $rc = Close(2)
Edited by Faithfulman (2006-10-18 02:02 AM)
|
Top
|
|
|
|
#169477 - 2006-10-18 06:54 AM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Does anyone have any ideas on this??
|
Top
|
|
|
|
#169479 - 2006-10-18 07:55 AM
Re: XML - writing to existing file
|
Gargoyle
MM club member
Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
|
Quote:
Okay, from this
Quote: --------------------------------------------------------------------------------
This is too cool
--------------------------------------------------------------------------------
to
Quote: --------------------------------------------------------------------------------
This is too cool
--------------------------------------------------------------------------------
I am missing something, they both look exactly the same to me.
|
Top
|
|
|
|
#169481 - 2006-10-18 02:34 PM
Re: XML - writing to existing file
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
mart, 'Else' is redundant Code:
Break on ; $sourcefile = "d:\XMLfile.xml" $newfile = "d:\newXMLfile.xml" ; $rc = Open (1, $sourcefile, 2) $rc = Open (2, $newfile, 5) ; $line = ReadLine (1) While @ERROR = 0 If InStr ($line, "This is too cool") $line = Split($line, "This is too cool") $line = Join ($line, "Dude") EndIf $rc = WriteLine (2, $line + @CRLF) $line = ReadLine (1) Loop ; $rc = Close(1) $rc = Close(2)
|
Top
|
|
|
|
#169483 - 2006-10-18 06:36 PM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Okay guys, yes this did work ... but not exactly how I thought it was going to.
I want to be able to take whatever is in the "<'test'>" tags and replace it with whatever I choose to. So basically, if I have this:
Code:
< Receipt > < test >D:\windows\folder1\< /test > < /Receipt >
or if I have
Code:
< Receipt > < test >C:\juicyfruit\dumplingsandgravey\< /test > < /Receipt >
I want to be able to strip that whole thing out and replace it with:
Code:
< Receipt > < test >D:\windows\folder44< /test > < /Receipt >
Is there a way to just find the line that holds the "< test >" tags and replace what's between the "< test >" tags?
Thanks,
Faithful
P.S. The forum keeps removing my tags as soon as post, sorry about the extra spaces.
|
Top
|
|
|
|
#169484 - 2006-10-18 08:15 PM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Anyone have any thoughts on this?
|
Top
|
|
|
|
#169486 - 2006-10-18 08:23 PM
Re: XML - writing to existing file
|
Faithfulman
Getting the hang of it
Registered: 2005-02-22
Posts: 68
|
Right but the line could be many different things. So, If I could replace the whole line that would be fine. Just not sure how to go about replacing the whole line? Any thoughts?
Thanks,
Faithful
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 918 anonymous users online.
|
|
|