Archive: nsisXML::insertBefore usage


nsisXML::insertBefore usage
Hi all,

I try nsisXML::insertBefore function. readme file says this function inserts new child node to the left of node $3. But which function does set the node $3?

I will be very pleasure if you can explain with a sample.

Best regards,


Hello

First you have to get the node reference you want to insert to the left of... for example with createElement or select which fills variable $2.
Then you can simply use StrCpy to copy this reference into variable $3.
Then create your new node (for example with createElement) into $2, and use insertBefore to insert node $2 to the left of $3

see attached sample script.
compare it with the sample.nsi from nsisXML
http://wiz0u.free.fr/prog/nsisXML/

I hope this is clearer now :)

Wizou


Thank you very much but a runtime error is thrown
Dear Wizou, thank you so much for quickly and quite clearer response.

I want to update james server's config.xml file. I have try the following code due to your explanations:

nsisXML::create /NOUNLOAD
nsisXML::load /NOUNLOAD "C:\james231\apps\james\SAR-INF\config.xml"
nsisXML::select /NOUNLOAD '/config/spoolmanager/processor[@name="root"]/threads'
nsisXML:: parentNode /NOUNLOAD
# parent node are loaded to $1

nsisXML::select /NOUNLOAD '/config/spoolmanager/processor[@name="root"]/mailet[@match="HasMailAttributeWithValue=org.apache.james.infected, true" and @class="ToProcessor"]'
StrCpy $3 $2
# left node loaded to $3

nsisXML::createElement "special"
nsisXML::setAttribute /NOUNLOAD "match" "HostIs=exp"
nsisXML::setAttribute /NOUNLOAD "class" "GlobalMailet"
nsisXML::setText "exp"
# new node loaded to $2

nsisXML::insertBefore ; insert this <> node before $3
nsisXML::save "C:\james231\apps\james\SAR-INF\config.xml"

But when I compile and then test the script with EclipseNSIS, a runtime error is thrown. If I remove the insertBefore line and then test, no error.

Where do I do wrong? Thanks so much for your helps.

Best regards,

Yasemin


I think your second select statement must be somewhat wrong and return 0 because the specified XPath can't match any node.
Then insertBefore crashes because $3 contains 0
Try to add a MessageBox MB_OK "select returned $3" after the select to check that.
If it is 0, correct the XPath expression according to config.xml.

Also I don't see the point in your first select/parentNode statements as you don't really use $1 and your second select statement is using an absolute XPath expression.


thanks so much :) solved the problem
Hello Wizou, really thank you so much. I saw my error thanks to you. The problem arised from 2nd select expression because it caused updating $1. When parent node ($1 - the result of 1nd select) copied a temporary variable and then assigned to $1 from temp after 2nd select, solved the problem.

Thanks you for helps and explanations:)


Best regards,

Yasemin