Skip to content
⌘ NSIS Forum Archive

XML plugin

118 posts

guineapig#
Hi all,
I'm trying to use the xml plugin with nsis unicode v2.46 but it does not work.
The plugin does not load the xml file and return error code is an unknown char (the classic square char). Before spending too much time on it, I would like to know if there are some known compatibility issue.

thank you very much
gringoloco023#
try the NsisXML plug-in by Wizou, although it works great and also works with utf-16 xml files, it is msxml.dll depended !

Another possibility which I personally am very happy with is calling the Xml plug-in from instructor with a special header file for unicode nsis. but utf-16 files are not supported (alternatively they could be re-encoded to utf-8 and back again)
ssamuels_sv#
Remote XML File

I'm curious if anyone knows how to link this plug-in with a file that is hosted on a server. I know that the plug-in can read a file locally, but it would be helpful in my application to read the file remotely rather than have to distribute the file along with the installer. I want to use a generic installer and have it go grab the information that it needs.

Or does anyone know of another plug-in that will simply grab a remote file so that this plug-in can parse the XML tree?

Thanks in advance.
ssamuels_sv#
Thank you. I just figured that out and was going to say, never mind. Thanks for the quick reply. I tried inetc, but I'll take a look at NSISdl as well.
loyalp#
comments

I've just started using this plugin, and so far have it doing everything I need for inserting some new lines in a web.config file. I do not see to be able to figure out how to get a new comment inserted, however.

xml file is setup like:

<?xml version="1.0" ?>
<configuration>
<appSettings>
<add key="LogLevel" value="4" />
</appSettings>
</configuration>

I'm adding several new <add key= statements, but would also like to insert a comment at the same level.

Final product would be:

<?xml version="1.0" ?>
<configuration>
<appSettings>
<!--Some Comment-->
<add key="LogLevel" value="4" />
<add key="something" value="" />
<add key="something" value="" />
<add key="something" value="" />
<add key="something" value="" />
</appSettings>
</configuration>

I've tried:


${xml::LoadFile} "$INSTDIR\Web.config" $0
${xml::RootElement} $0 $1
${xml::XPathNode} "/configuration/appSettings" $0
${xml::CreateNode} "<'!-- Some Comment--'/>" $4
${xml::InsertEndChild} $4 $5

and also ${xml::CreateNode} "<'!-- Some Comment--'/>" $4.

What am I missing here?
fefer#
I create Installer that load xml file and read the node value

I stop the installer running, I change the xml file node value and I run the Installer again

at the second time the installer shows me that the value didn't change, and when I run oit again it's show me the value changed

Way the istaller show me the prev value?
T.Slappy#
The XML file is packed inside installer or not?
Maybe other process/application is working with this file too?
gretty#
I am attempting to add a large XML element to an existing XML file but it keeps failing to add the new node. What do you think is going wrong?

I've tried making the XML element smaller(reducing OVERRIDES_TEXT) and that allows me to successfully add the new element/node to the XML file. But I need all the text(xml) in OVERRIDES_TEXT to be added to the element(I cant remove any of it).

Any ideas on how I could achieve this?


${xml::LoadFile} "${xmlFileName}" $R0
${xml::GotoPath} "${elementPath}" $R0
${xml::CreateNode} '<Overrides>${OVERRIDES_TEXT}</Overrides>' $R0
${xml::InsertAfterNode} $R0 $R1 # always fails here $R1 = -1

# below is the string that causes the error
!define OVERRIDES_TEXT "<Override>\
<Key>EXDS_CUSTOMISATION_REVISION</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>CUSTOMER_USER_4D</Key>\
<Value>C:\12d\10.00\Customers\EXDS_Customisation\EXDS_User</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>CUSTOMER_LIB_4D</Key>\
<Value>C:\12d\10.00\Customers\EXDS_Customisation\EXDS_User_Lib</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>USER_4D</Key>\
<Value>C:\12d\10.00\User</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>USER_LIB_4D</Key>\
<Value>C:\12d\10.00\User_Lib</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>EXDS_USER_LIB</Key>\
<Value></Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>EXDS_USER</Key>\
<Value></Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>VERSION_12D_MODEL</Key>\
<Value>10.0</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>CPATH</Key>\
<Value>$$CUSTOMER_LIB_4D:$$CUSTOMER_USER_4D:$$USER_LIB_4D:$$USER_4D:$$LIB_4D:$$SET_UPS_4D</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>AUTHORIZATION_4D</Key>\
<Value>C:\12d\10.00\nodes.4d</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>USE_NAMES_COMMENT_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>FILE_READ_ADD_TO_VIEW_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>GENIO_WILDCARD_4D</Key>\
<Value>*.inp</Value>\
<State>1</State>\
</Override>\
<Override>\
<Key>RUN_MACROS_FILE_4D</Key>\
<Value>$$USER\macros.4d</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>PROJECT_DETAILS_4D</Key>\
<Value>$$USER\project_details.dtl</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>REPORT_HEADER_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>AUTO_TIN_SYNC_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>AUTO_MODEL_SYNC_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>SHARE_CHECK_INTERVAL_4D</Key>\
<Value>300</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>SHARED_ELEMENT_COLOUR_4D</Key>\
<Value>blue</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>SHARING_ELEMENT_COLOUR_4D</Key>\
<Value>red</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>DEFAULT_PLAN_PLOT_SCALE_4D</Key>\
<Value>500</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>DWG_PLOT_SEED_FILE_4D</Key>\
<Value>$$USER\EXDS_Acad_Plot_Template.dwt</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>DEFAULT_RASTER_DPI_4D</Key>\
<Value>600</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>OPENGL_VIEW_BACKING_STORE_4D</Key>\
<Value>2</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>MULTI_LINE_TEXT_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>NEW_MTF_EDITOR_AUTOPAN_DEFAULT_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>WINDOWS_VEHICLE_PATH_4D</Key>\
<Value>C:\Apps\VPath</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>chainage_equality_4d</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>XML_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>\
<Override>\
<Key>USE_V10_BOXING_CALCS_4D</Key>\
<Value>1</Value>\
<State>0</State>\
</Override>"
MSG#
Please don't paste such huge amounts of text in a post - use either an attachment or pastebin.

Your problem is probably that the string you're trying to write is much bigger than ${NSIS_MAX_STRLEN}. The default NSIS builds have a max length of 1024 bytes. There is also a large string build of NSIS which supports op to 8192 bytes. But I don't think you're using the xml plugin properly. I've never used it myself, but what you're doing is telling it to write a single, huge textline "<Override><Key>EXDS_CUSTOMISATION_REVISION</Key><Value>1</Value><State>0</State></Override><Override><Key>CUSTOMER_USER_4D</Key><Value>C:\12d\10.00\Customers\EXDS_Customisation\EXDS_User</Value>" etcetc. You could use FileWrite for that, so I doubt that's how the XML plugin is supposed to be used.
dacode#
@Instructor -

I would like to use this XML plugin as well as the Registry plugin by instructor, however, I do not see any license.

Are all NSIS plugins licensed under the NSIS license?
PoRtAbLe_StEaLtH#
Great Help

Originally Posted by xbarns View Post
Hi all,

i need to edit a xml structure like this

<Configuration
<ConfigModule name="BlaBla">
 </ConfigModule>
 <ConfigModule name="FirebirdBridge" DefaultConfig="FALSE">
    <Section name="FirebirdBridge" description="Configuration for Firebird DB Bridge">
      <Data name="Host" type="string">127.0.0.1</Data>
      <Data name="Database" type="string">C:\Program Files\Test\Database\Test.FDB</Data>
      <Data name="User" type="string">User</Data>
      <Data name="Password" type="string">Password</Data>
    </Section>
  </ConfigModule>
</Configuration> 
In order to change the "<Data name="Database" type="string">C:\Program Files\Test\Database\Test.FDB</Data>" is there any other way then looping through the nodes and comparing attributes ?

i am already looping through the "ConfigModule" Nodes and comparing, is there an easier way?

Here is the code i have so far:

${xml::LoadFile} "$EXEDIR\scMaster.ctf" $0
loop:
${xml::FindNextElement} "ConfigModule" $0 $1
${xml::ElementPath} $0
${xml::GetAttribute} "name" $1 $2 
${IF} $1 == "FirebirdBridge"
        
    ${xml::GotoPath} "$0/Section/Data" $1
    Loop here again ?
         
         
${ELSE}
        Goto loop        
${ENDIF}
${xml::FindCloseElement}
${xml::SaveFile} "$EXEDIR\scMaster2.ctf" $0
${xml::Unload} 

Thanks for helping 🙂



thanks.. this helped me tremendously..
<Configuration
<ConfigModule name="BlaBla">
 </ConfigModule>
 <ConfigModule name="FirebirdBridge" DefaultConfig="FALSE">
    <Section name="FirebirdBridge" description="Configuration for Firebird DB Bridge">
      <Data name="Host" type="string">127.0.0.1</Data>
      <Data name="Database" type="string">C:\Program Files\Test\Database\Test.FDB</Data>
      <Data name="User" type="string">User</Data>
      <Data name="Password" type="string">Password</Data>
    </Section>
  </ConfigModule>
</Configuration> 
Correct XPath:
/Configuration/ConfigModule/Section/Data[@name="Host"]
I was using: (Wrong)
/Configuration/ConfigModule[@name="FirebirdBridge"]/Section[@name="FirebirdBridge"]/Data[@name="Host"]
xbarns#
Accidental Replace of &quot; (double quote)

Hi All,

i use the plugin to replace certain values in an unattend.xml (used for Windows NT6 deployment, e.g. License Key, Company name aso.).

But when i do this it will change a line

<CommandLine>%systemdrive%\ASetup\LockScr.exe "%systemdrive%\ASetup\asetup.bmp"</CommandLine>

to

<CommandLine>%systemdrive%\ASetup\LockScr.exe &quot;%systemdrive%\ASetup\asetup.bmp&quot;</CommandLine>

is there any way to preven the change from " to &quot; ?

It seems to happen as a "by product" since i do not edit anything near the occurence of the <CommandLine> tags.

Thanks a lot, any help is appreciated....
x
awall#
Element data longer than 1024 bytes get truncated

Originally Posted by MSG View Post
Your problem is probably that the string you're trying to write is much bigger than ${NSIS_MAX_STRLEN}. The default NSIS builds have a max length of 1024 bytes. There is also a large string build of NSIS which supports op to 8192 bytes.
Hello, I have found this thread trying to fix an issue with XML plugin. I am dealing with XML containing big elements with about 2KB of base64 encoded data each.
When I read these data I only get the first 1023 bytes so I'm assuming this is due to the 1024 bytes string length limit in NSIS.
However I have updated the NSIS build with support for 8K long strings but data is still truncated to 1K.
My suspect is that the XML plugin should be updated as well to deal with 8K strings. Can anyone confirm?
And in case, do you have an idea on how to modify the XML plugin to support long strings?

Thanks
Andrea
dies#
Originally Posted by awall View Post
Hello, I have found this thread trying to fix an issue with XML plugin. I am dealing with XML containing big elements with about 2KB of base64 encoded data each.
When I read these data I only get the first 1023 bytes so I'm assuming this is due to the 1024 bytes string length limit in NSIS.
However I have updated the NSIS build with support for 8K long strings but data is still truncated to 1K.
My suspect is that the XML plugin should be updated as well to deal with 8K strings. Can anyone confirm?
And in case, do you have an idea on how to modify the XML plugin to support long strings?

Thanks
Andrea
awall, length of output string just defined in the library

/* Defines */
#define NSIS_MAX_STRLEN 1024

To change max output length, you just need to change this value and rebuild.

By the way,
I'm succesfully builded x64 (also upgraded TinyXML to 2.6.2), if someone need it just pm me and I will send it.
P.S.
Just don't want to publish it because I'm not an author
currarpickt#
Remove several nodes

Hi, I am using this plugin to read an xml file but I have a problem with RemoveNode.
I need to compare an xml file with a text file and if I found a string that doesn't belong in the text file, I will delete it from xml file. But, after I remove one node, the looping always stop because it cannot find the NextSibling. Any idea how to continue the loop?

${xml::LoadFile} "$TEMP\$XMLFile" $0
${xml::GotoPath} "/unattend/servicing/package" $0
${xml::FirstChild} "assemblyIdentity" $1 $0
${xml::NextSibling} "selection" $7 $0
${While} $0 == 0
${xml::GetAttribute} "name" $3 $4
Push $TEMP\featurelist.txt
Push $3
Call FileSearch
Pop $0 #Number of times found throughout
Pop $1 #Number of lines found on

${IF} $0 == 0
${xml::RemoveNode} $7
${ENDIF}

${xml::NextSibling} "selection" $7 $0
${EndWhile}
${xml::SaveFile} "$TEMP\$XMLFile" $0
${xml::NodeHandle} $0
${xml::Unload}
traal#
Don't remove &quot;xml-stylesheet&quot; declaration

Before calling ${xml::SaveFile} on an existing .xml file:

<?xml-stylesheet type="text/xsl" href="MyStylesheet.xslt"?>
After calling ${xml::SaveFile}:

<?xml ?>
Please fix this.

Also, the plugin doesn't preserve whitespace: it removes blank lines, puts all attributes on the same line as the element, and I think it also modifies indenting.
Хамик#
Tell me, please, how do I change the parameter <Temp Folder ScreenShots>? Requires overwrite value. Thank you!

xml file example:

<ScreenSettings xmlns:xsi="http://www.w.org/200/XMLSchem-instance" xmlns:xsd="http://www.w.org/200/XMLSchem">
    <Version>1</Version>
    <AutoStart>false</AutoStart>
    <CheckForUpdate>false</CheckForUpdate>
    <Fum>false</Fum>
    <Language>Russian</Language>
    <CurrentRectSettingsIndex>-1</CurrentRectSettingsIndex>
    <TempFolderScreenShots>C:\Users\HAM\Pictures\Screen</TempFolderScreenShots>
</ScreenSettings> 
Anders#
Originally Posted by Хамик View Post
Tell me, please, how do I change the parameter <Temp Folder ScreenShots>? Requires overwrite value. Thank you!
It would help if you posted the code you already have tried and maybe we can fill in the missing pieces...
Kyle_1988#
Okay, I figured out that it's just !define.

Next question. Does GotoPath use Xpath? If not, is there any way to locate a node based on an attribute value using this plugin?
Kyle_1988#
Okay, I've examined the C++ source code and determined that the path parsing is fairly basic and does not use XPath. Can anyone recommend a plugin that allows me to navigate to a node based on an attribute value?
Anders#
Both http://nsis.sourceforge.net/NsisXML_plug-in_(by_Wizou) and http://nsis.sourceforge.net/NsisXML_plug-in_(by_Joel) supports XPath.
devouk#
Hi, Wondering if someone can shed some light.... I am a noobie with nsis but currently need to install and alter an xml file to included local users store location

I have tried to learn and use the 3 various main xml plugins and they have driven me to disspare lol.

I had an understanding of xml but learning XPATH and also the syntax of the plugins / NSIS

I have tried so many combination and using detailprint to show results hence my thousands of perminatations failing.

So wondering if someone can point me in the right direction..

So here is a shorten xml file

<?xml version="1.0" encoding="UTF-8"?>
<ConfigFile>
<configuration name="default">
<section name="Settings">
<value name="FirstStart">0</value>
<value name="Language">internal</value>
<value name="Encoder">3</value>
<value name="EncoderOutDir"></value>
<value name="EncoderFilenamePattern">&lt;album&gt;\&lt;track&gt; - &lt;artist&gt; - &lt;title&gt;</value>
<value name="EncodeOnTheFly">1</value>

</section>
</configuration>
</ConfigFile>

So as you can see they aren't individual patterns but a repeated pattern
I am wanting to pass the local users "my music" folder to the xml under ENCODEROUTDIR as far as I understand from xpath I should be able to use this as explicit / absolute

/configfile/configuration[@name="default"]/section[@name="settings"]/value[@name="EncodeOnTheFly"]
so my first issue

${xml::GotoPath} "/configfile/configuration[@name="default"]/section[@name="settings"]/value[@name="EncodeOnTheFly"]" $0 
Now this brings a parameter error due to the xml plugin due to the additional " marks in the command, what would be the correct way to call this ? <synatax issue>

I presume I could also use this abbreviated way as

${xml::GotoPath} "/value[@name="EncodeOnTheFly"]" $0 
Anyway at any point I have drilled down and used [@data] it screws up.

Then if I want to pass a constant $MyMusic and any pointers on the best way of doing this correctly then that will help me.

Which is the better xml plugin to use and kind to learn ?

Any advice would be really appreciated as I losing faith in my own abilities.

Thank you

devo
Kyle_1988#
No need to write a long question. We had just established on this thread that this plugin doesn't support XPath. I ended up using Joel's plugin. Scroll up for details.