Skip to content
⌘ NSIS Forum Archive

XML Modification

6 posts

zewari#

XML Modification

I have an installer that needs to modify an existing XML document. The document currently has a node structure that looks like this:

<TypeMapping>
<Type>
<Name>name a</Name>
<Namespace>namespace a</Namespace>
<CLSID>clsid a</CLSID>
</Type>
<Type>
<Name>name b</Name>
<Namespace>namespace b</Namespace>
<CLSID>clsid b</CLSID>
</Type>
</TypeMapping>
My installer needs to add a couple of type elements with their own Name, Namespace, and CLSID child elements. I've tried to use wizou's XML plugin, but was not seeing my new entry added to the XML file. Here's what I tested:


Section "Test"
nsisXML::create
nsisXML::load "sample.dat" ;file in the same directory as installer
nsisXML::select "main"
nsisXML::createElement "Type"
nsisXML::appendChild
StrCpy $1 $2
nsisXML::createElement "Name"
nsisXML::setText "MultiDirectionalHillshadeFunction"
nsisXML::appendChild
nsisXML::createElement "Namespace"
nsisXML::setText "url"
nsisXML::appendChild
nsisXML::createElement "CLSID"
nsisXML::setText "{clsid number}"
nsisXML::appendChild
nsisXML::save "Sample.xml"
SectionEnd
Would anyone care to suggest an alternate method, or maybe fill me in on what I'm doing wrong with the plugin from wizou? A lot of the threads I've read are a bit dated, so I wasn't sure what the best practice would be like when it comes to this sort of task.
JasonFriday13#
Perhaps it's the encoding of the source file, ie ansi, utf-8, or utf-16le?

Try creating a new file with nsisXML as a test and see what the encoding of it is.
zewari#
Thanks for the suggestion, I realized I was creating a new file called sample.xml instead of sample.dat! I can create a new XML file but am finding my installer crash when I use nsisXML::load "Sample.dat". This is what I get from the Windows event log:

Faulting module name: KERNELBASE.dll, version: 6.3.9600.17415, time stamp: 0x54504ade
Exception code: 0xe06d7363
Fault offset: 0x00014598
Is there an alternate method you can recommend for modifying an existing XML document? Should I just use some kind of text editing find/replace operation?
zewari#
It still crashes after I change the *.dat file to *.xml 🙁

Is there a method I can use to do a find and replace sort of operation on a text file?
JasonFriday13#
Like I said before, it might be the encoding of your file you are trying to modify (ansi, utf-8, utf-16le). So use the plugin to write a brand new test file, and check the encoding against your file to see if it matches or not.