Archive: Create multiple XML Nodes


Create multiple XML Nodes
Using xml.nsh plugin created by Instructor.
I am trying to create three similar Nodes at the end of Server/Services/Engine/Host. When I create just one Node everything works fine. When I generate multiples, the result is less than desirable.

My test script:
#XML Plugin Examples
Name "XMLTest"
OutFile "XMLTest.exe"
!include "XML.nsh"

# open section
section
; Example of usage

${xml::LoadFile} "C:\Contenta36Install\NSIS Scripts\test.xml" $0
${xml::GotoPath} "/config/local/host" $0
${xml::CreateNode} '<Context docBase="E:\ContentaView\" path="/servlets3"></Context>' $0
${xml::InsertEndChild} "$0" $0
${xml::CreateNode} '<Context docBase="G:\ContentaViewData\collections\NIAPS_ContentaView3.6\httpdocs\" path="/wietmsd"></Context>' $0
${xml::InsertEndChild} "$0" $0
${xml::CreateNode} '<Context docBase="G:\ContentaViewData\collections\" path="/collections"></Context>' $0
${xml::InsertEndChild} "$0" $0
${xml::SaveFile} "C:\Contenta36Install\NSIS Scripts\test.xml" $0
${xml::Unload} ; unload plugin
# end the section
SectionEnd

Test Results:
<config>
<local>
<host>
<Context docBase="E:\ContentaView\" path="/servlets3">
<Context docBase="G:\ContentaViewData\collections\NIAPS_ContentaView3.6\httpdocs\" path="/wietmsd">
<Context docBase="G:\ContentaViewData\collections\" path="/collections" />
</Context>
</Context>
</host>
</local>
</config>

Target Results for Production:
<Valve className="org.jboss.web.tomcat.tc5.jca.CachedConnectionValve" cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager" transactionManagerObjectName="jboss:service=TransactionManager" />

<Context docBase="E:\ContentaView\" path="/servlets3" />
<Context docBase="G:\ContentaViewData\collections\NIAPS_ContentaView3.6\httpdocs\" path="/wietmsd" />
<Context docBase="G:\ContentaViewData\collections\" path="/collections" />
</Host>
</Engine>
</Service>
</Server>
Notes for desired result:
The last three Context Nodes are added just before the closing Host Element without deleting any of the other Host children, i.e Valve.

Any suggestions would be gratefully appreciated.
Thank you in advance


After the first {InsertEndChild} you need to move the node forward by using {InsertAfterNode}.

The XML NSIS plugin has good documentation on usage.
Below I pasted a working solution to your problem.
(Variable changes didn't matter, so don't worry about that)

# open section
section
; Example of usage

${xml::LoadFile} "C:\Documents and Settings\Administrator\Desktop\NSI XML\test.xml" $0
${xml::GotoPath} "/config/local/host" $0
${xml::CreateNode} '<Context docBase="E:\ContentaView\" path="/servlets3"></Context>' $1
${xml::InsertEndChild} "$1" $0
${xml::CreateNode} '<Context docBase="G:\ContentaViewData\collections\NIAPS_ContentaView3.6\httpdocs\" path="/wietmsd"></Context>' $2
${xml::InsertAfterNode} "$2" $1
${xml::CreateNode} '<Context docBase="G:\ContentaViewData\collections\" path="/collections"></Context>' $3
${xml::InsertAfterNode} "$3" $2
${xml::SaveFile} "C:\Documents and Settings\Administrator\Desktop\NSI XML\test.xml" $0
${xml::Unload} ; unload plugin
# end the section
SectionEnd