Old 23rd October 2015, 01:17   #1
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
Question 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:

code:
<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:

code:

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.
zewari is offline   Reply With Quote
Old 24th October 2015, 04:45   #2
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 884
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.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 29th October 2015, 02:02   #3
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
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:

code:
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 is offline   Reply With Quote
Old 29th October 2015, 05:32   #4
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 884
Maybe the plugin only accepts files with the .xml extension?

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 29th October 2015, 19:10   #5
zewari
Junior Member
 
Join Date: Mar 2014
Posts: 17
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?
zewari is offline   Reply With Quote
Old 30th October 2015, 00:22   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 884
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.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
xml

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump