Archive: XML editing,code from archives but not working


XML editing,code from archives but not working
  Code is from Archive.What I need to do it to call this script from my main installer file to make changes in my 2 XML files.
This is code in my main installer file but it's not working,i am doing something wrong but can't figure out
In WriteXML I get script,StringA,StringB value coorect but file.name and filnenew.xml comes as null.Please help.
Code attached.
What I need is that I should be able to send sourcefile name,destination file name,string to be replaced,new string from my main installer file to Writexml and get the final output in destination file name. Thank in advance

push "StringA"
push "StringB"
push "file.xml"
push "filenew.xml"


; Some code to adjust settings in XML file.
;
; By Hendri Adriaens.
; HendriAdriaens@hotmail.com
!define TEMP1 $R0 ;Temp variable
!define TEMP2 $R1 ;Temp variable
!define TEMP3 $R2 ;Temp variable
!define TEMP4 $R3 ;Temp variable
;outfile WriteXML.exe
;name WriteXML
; push sourcefile
; push destfile
; push search string
; push new string

function ParseXML
;MessageBox MB_YESNO "This will modify studio.txt and put output to temp.tmp.$\r$\nContinue?" IdNo Quiting

Exch $0 ;newString
MessageBox MB_OK $0
Exch
Exch $1 ;search string
MessageBox MB_OK $1
Exch
Exch $2 ;source file
MessageBox MB_OK $2
Exch
Exch $3 ;destfile
MessageBox MB_OK $3


FileOpen $R0 "$3" "r"
FileOpen $R1 "$4" "w"
MessageBox MB_OK $R0
MessageBox MB_OK $R1


Loop:
FileRead $R0 $R2
StrCmp $R2 "" ExitLoop
push $R2
push $1
Call StrStrH
Pop $R3
StrCmp $R3 $R2 NotFound
FileWrite $R1 '$R3"$1" value="$2" />$\r$\n'
GoTo Loop
NotFound:
FileWrite $R1 $R2
Goto Loop
ExitLoop:
FileClose $R0
FileClose $R1
Quiting:
Quit
functionend

Function StrStrH
;Modified StrStr function from functions.htm
Exch $1
Exch
Exch $2
Push $3
Push $4
Push $5
StrLen $3 $1
StrCpy $4 0
loop:
StrCpy $5 $2 $3 $4
StrCmp $5 $1 done
StrCmp $5 "" done
IntOp $4 $4 + 1
Goto loop
done:
StrCpy $1 $2 $4
Pop $5
Pop $4
Pop $3
Pop $2
Exch $1
FunctionEnd

section
sectionend


In the first place, you seem to be pushing your arguments in the wrong order.
The documentation for the script says:


; push sourcefile
; push destfile
; push search string
; push new string


So you should push in that order.

Secondly, the ParseXML function seems to be extracting the arguments incorrectly.
It should be doing:


Exch $0 ;newString
MessageBox MB_OK $0
Exch
Exch $1 ;search string
MessageBox MB_OK $1
Exch
Exch 2
Exch $2 ;dest file
Exch
Exch 2
Exch 3
Exch $3 ;source file


Please correct me if I am wrong.

XML editing..............................
  I put that documentation in and I think stack is LAST IN FIRST OUT, correct me if I am wrong. That's what I assume and I get the valye for STRINGA and STRINGB correct in the function but just not the 2 files. It could be the extraction problem,I will look into it more.Anybody else ?
Thanks for your reply


I think that you should use Pop to get the value on the stack instead of Exch. Exch exchanges the top value on the stack with the value in the variable. Pop moves the value on the stack to the variable, so that the next value on the stack becomes the top value:

push "StringA"

>push "StringB"
>push "file.xml"
>push "filenew.xml"
The stack contains:
filenew.xml
file.xml
StringB
StringA


Then, using Pop:

Pop $0

MessageBox MB_OK$0
>
The stack contains:
file.xml
StringB
StringA

And the message box should show: filenew.xml

Then pop again, and so on.

I'm not sure about the order in which the items come on the stack and leave stack. But I think that Push puts the item on top of the stack, and Pop takes the top item of the stack.

If Pop is used to get the values from the stack, you lose the current values in the registers- which could have bad consequences later.
Another problem I noticed with ParseXML is that it is not restoring the register values when it completes.


The stack operations in this function are wrong. Where did you take it from? I can't find it in the archive...

Please attach large scripts next time.