WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > XML plugin
Pages (2): « 1 [2]   Last Thread   Next Thread
Author
Thread Post New Thread    Post A Reply
JDaniels13
Junior Member

Registered: Aug 2006
From: Olympia WA

A .NET 1.1 config file used in testing

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="@CBR_CBRFILE" value="Initialization.cbr" />
<!-- Environment Setup Type should be "PROD" or "DEV" or "QA" -->
<add key="Site.Environment" value="QA" />
<!-- Environment Setup End -->
<!-- Security Setup -->
<add key="ConnectionString" value="Case sensitive, shouldn't match this" />
<!--Socket Setup (used for refund transaction) -->
<!--add key="SocketPort" value="3805" / -->
<!--add key="SocketTimeout" value="30000" / -->
</appSettings>
</configuration>

So after calling the macro, the file would be like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="@CBR_CBRFILE" value="Initialization.cbr" />
<!-- Environment Setup Type should be "PROD" or "DEV" or "QA" -->
<add key="Site.Environment" value="QA" />
<!-- Environment Setup End -->
<!-- Security Setup -->
<add key="ConnectionString" value="Case sensitive, shouldn't match this" />
<add key="connectionString" value="This is the one that should get matched and changed" />
<!--Socket Setup (used for refund transaction) -->
<!--add key="SocketPort" value="3805" / -->
<!--add key="SocketTimeout" value="30000" / -->
</appSettings>
</configuration>


The problem with .NET config files is that all the elements in the appsettings section are "<add ", so you have to then navigate through each element looking for the attributes "key", to find the node you want, and then once you find it, set the "value" attribute for that node. Thus all the code for navigating within the duplicate-named "<add " elements.

If someone has an easier way, please share it! I didn't see an NSIS plugin for .NET config file editing, is there one I missed?

Quick Link | Report this post to a moderator | IP: Logged

JDaniels13 is offline Old Post 08-24-2006 09:58 PM
Click Here to See the Profile for JDaniels13 Click here to Send JDaniels13 a Private Message Find more posts by JDaniels13 Add JDaniels13 to your buddy list Edit/Delete Message Reply w/Quote
JDaniels13
Junior Member

Registered: Aug 2006
From: Olympia WA

The thing that the nsisXML has going for it is it supports XPath, including the attribute specs in the XPath query. I understand there is a Tiny XPath company to TinyXML, but the XPath functionality is not integrated into the XML plugin.

Here's what I had for the nsisXML plugin version of the .NET 1.1 config file editing macro:

!macro EditDotNETConfigFile2 ConfigFile KeyXPath KeyName KeyValue
SetPluginUnload alwaysoff
nsisXML::create
nsisXML::load ${ConfigFile}
nsisXML::select ${KeyXPath} /* '/main/child[@attrib="value2"]' */
IntCmp $2 0 notFound
; nsisXML::removeChild
nsisXML::createElement "add"
nsisXML::setText " "
nsisXML::appendChild
nsisXML::getAttribute ${KeyName}
DetailPrint "Attribute ${KeyName} is $3"
nsisXML::setAttribute "key" ${KeyName}
nsisXML::setAttribute "value" ${KeyValue}
MessageBox MB_OK "attribute set"
SetPluginUnload manual
nsisXML::save ${ConfigFile}
Goto end
notFound:
MessageBox MB_OK "XPath not resolved"
DetailPrint "XPath not resolved"
end:
!macroend

; Called like this:
!insertmacro EditDotNETConfigFile2 "c:\InetPub\wwwroot\MyWebSite\Web2.config" '/configuration/appSettings/add[@key="connectionString"]' "connectionString" "TestConnString2"

It was very handy to use XPath to go right to the "<add " element node with the "key= " attribute value I wanted. Would have saved much of the navigation code I had to write in the (TinyXML-based) XML plugin.

Quick Link | Report this post to a moderator | IP: Logged

JDaniels13 is offline Old Post 08-24-2006 10:41 PM
Click Here to See the Profile for JDaniels13 Click here to Send JDaniels13 a Private Message Find more posts by JDaniels13 Add JDaniels13 to your buddy list Edit/Delete Message Reply w/Quote
mtyler
Junior Member

Registered: Sep 2006
From: San Diego

I have integrated TinyXPath with this plugin

If anyone is interested, I have integrated the TinyXPath library with this plugin. It worked like a charm the very first time (surprised the heck out of me). Here are the steps:

1) Download TinyXPath from
URL submitted by user.

2) Compile the TinyXPath LIB according to the instructions here URL submitted by user.

3) Copy the tinyxpath.lib file along with all the TinyXPath .h (header files), excluding the TinyXML header files, to the XML Plugin source directory.

4) Add

code:
#include "xpath_static.h"
to the top of xml.cpp (XML Plugin source file)

5) Add the following code block to xml.cpp:

code:
extern "C" void __declspec(dllexport) _GotoXPath(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); { popstring(szBuf); nodeTmp = TinyXPath::XNp_xpath_node(node, szBuf); if(nodeTmp) { node=nodeTmp; pushstring("0"); return; } else { pushstring("-1"); } } }



6) Compile the XML Plugin source to the xml.dll file. Place the new xml.dll file in the NSIS/plugins directory (duh!)

7) Add the following code block to the XML.nsh file located in the NSIS/include directory:

code:
!define xml::GotoXPath `!insertmacro xml::GotoXPath` !macro xml::GotoXPath _PATH _ERR xml::_GotoXPath /NOUNLOAD `${_PATH}` Pop ${_ERR} !macroend


Viola! You're done. Use
code:
${xml::GotoXPath} "path" $errvar
in your installer script and the current node gets changed to the first node matching the XPath expression. If I have time, or someone else beats me to it, iterative expression matching could easily be added by storing the XPath state (by using the xpath_processor.h rather than xpath_static.h).

Ask if you need any help. Let me know if this helps. And thank you "Instructor" for the Xml Plugin (way better than the rest of them)

Quick Link | Report this post to a moderator | IP: Logged

mtyler is offline Old Post 09-06-2006 05:10 PM
Click Here to See the Profile for mtyler Click here to Send mtyler a Private Message Click Here to Email mtyler Find more posts by mtyler Add mtyler to your buddy list Edit/Delete Message Reply w/Quote
JDaniels13
Junior Member

Registered: Aug 2006
From: Olympia WA

Thanks for your efforts! I'm not very handy with C++ builds; could you post the resulting XML.dll here?

Quick Link | Report this post to a moderator | IP: Logged

JDaniels13 is offline Old Post 09-06-2006 05:48 PM
Click Here to See the Profile for JDaniels13 Click here to Send JDaniels13 a Private Message Find more posts by JDaniels13 Add JDaniels13 to your buddy list Edit/Delete Message Reply w/Quote
mtyler
Junior Member

Registered: Sep 2006
From: San Diego

Here is the new xml.dll file

This site will not allow me to upload a DLL. I've zipped to see if it will accept it. You will need to modify xml.nsh according to my message.

Let me know if it works for you.

Attachment: xml.zip
This has been downloaded 448 time(s).

Quick Link | Report this post to a moderator | IP: Logged

mtyler is offline Old Post 09-06-2006 06:29 PM
Click Here to See the Profile for mtyler Click here to Send mtyler a Private Message Click Here to Email mtyler Find more posts by mtyler Add mtyler to your buddy list Edit/Delete Message Reply w/Quote
mtyler
Junior Member

Registered: Sep 2006
From: San Diego

Exclamation

PLEASE NOTE:

I hope that I have not overstepped my bounds by providing a modified version of xml.dll to this forum. The modification is based on the latest code base from "Instructor" and TinyXPath, but there are no promises of accuracy, reliability or safety, expressed or implied. Use at your own risk!

It would be nice if "Instructor" integrated this addition into the next build of his XML Plugin, giving it full XPath capabilities.

Quick Link | Report this post to a moderator | IP: Logged

mtyler is offline Old Post 09-07-2006 12:43 AM
Click Here to See the Profile for mtyler Click here to Send mtyler a Private Message Click Here to Email mtyler Find more posts by mtyler Add mtyler to your buddy list Edit/Delete Message Reply w/Quote
jeichhorn
Junior Member

Registered: Jun 2005
From:

I am trying to use the ${xml::GotoXPath} command added by mtyler.

Here is my test.xml:

code:
<?xml version="1.0" encoding="utf-8" ?> <test> <c1>content1</c1> <c2> <c3>c3_content1</c3> <c3>c3_content2</c3> <c3>c3_content3</c3> </c2> </test>


I am trying to select the element /test/c2/c3 with the content 'c2_content2'.

When i use the xpath
code:
${xml::GotoXPath} "//c3[text()='c3_content2']" $0

the element is selected as expected, but when i use
code:
${xml::GotoXPath} "/test/c2/c3[text()='c3_content2']" $0

it does not find the element (result is -1).

Do i use the GotoXPath function in a wrong way in my second example?

Thanks for help.

Jörg

Quick Link | Report this post to a moderator | IP: Logged

jeichhorn is offline Old Post 09-08-2006 07:55 AM
Click Here to See the Profile for jeichhorn Click here to Send jeichhorn a Private Message Find more posts by jeichhorn Add jeichhorn to your buddy list Edit/Delete Message Reply w/Quote
mtyler
Junior Member

Registered: Sep 2006
From: San Diego

The immediate workaround for your problem is to execute

code:
${xml::RootElement} $1 $0
after loading the document and before conducting any static XPath queries that begin with the root element. Any XPath that is based on the top level element will work, including yours.

The way the TinyXML works is to have a node above the top level element for the document itself. From this node you can get the document name and access XML comments that are outside the scope of the top level element. The XML plugin maintains it state as the current or last node that was read. This enables you to jump around from a relative perspective. But, from a technical perspective, conducting a static XPath query from the document node will not work.

I considered modifying the GotoXPath function to account for this, but I think that it will defeat the purpose of the document node. So use the workaround specified above or use the XPath query Descendant notation along with the root element (even though this is not entirely accurate; you should use xml::RootElement):
code:
//test/c2/c3[text()='c3_content2']


The original GotoPath function looks for a leading slash in the path designation and moves the current node to the root element before it locates the desired element. This works well for this function because it is a simple navigation function. The TinyXPath library is a robust XPath processor that will not benefit from the same logic used by the GotoPath function. Therefore, the suggestions I made above should become the norm.

As usual, I hope that this has helped. Feel free to ask for assistance. I am appreciative of all the great tools and technologies supported by this community.

Quick Link | Report this post to a moderator | IP: Logged

mtyler is offline Old Post 09-08-2006 05:01 PM
Click Here to See the Profile for mtyler Click here to Send mtyler a Private Message Click Here to Email mtyler Find more posts by mtyler Add mtyler to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

Changed: Compiled statically without msvcrt.lib, now plugin work on Win95.
Added: Integrated TinyXPath v1.2.4 (thanks mtyler).
Added: ${xml::XPathString} -compute a string XPath expression.
Added: ${xml::XPathNode} -compute a node XPath expression and goes to it.
Added: ${xml::XPathAttribute} -compute an attribute XPath expression and goes to it.
Added: ${xml::CurrentAttribute} -returns name and value of the current attribute.
Updated: TinyXml to v2.5.1
Updated: StackFunc.h to v2.0


"XML" plugin v1.8

Download from Wiki

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 09-10-2006 01:48 PM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
rtpHarry
Junior Member

Registered: Nov 2006
From: UK

possible bug in system

I almost abandoned this plugin yesterday when I was writing my installer. Now I have found a work around for it and I think its a great plugin again!

The problem arose when I tried to open an xml file for the second time. The first time I loaded the file (through a function attached to a custom page) it worked fine with this code (as I see it used in the forums as well):

PHP:

${xml::LoadFile} "client-list.xml" $0



The second time I used it was in a Section (for the install files part) and it failed with -1 every time until I saw somebody suggest for a different problem to prepend $EXEDIR to the start which fixed it.

PHP:

${xml::LoadFile} "$EXEDIRclient-list.xml" $8

Quick Link | Report this post to a moderator | IP: Logged

rtpHarry is offline Old Post 11-24-2006 11:50 AM
Click Here to See the Profile for rtpHarry Click here to Send rtpHarry a Private Message Find more posts by rtpHarry Add rtpHarry to your buddy list Edit/Delete Message Reply w/Quote
atul123
Junior Member

Registered: Dec 2006
From:

Where can I find examples of "How to use this XML plugin?"

Quick Link | Report this post to a moderator | IP: Logged

atul123 is offline Old Post 12-06-2006 02:02 PM
Click Here to See the Profile for atul123 Click here to Send atul123 a Private Message Click Here to Email atul123 Find more posts by atul123 Add atul123 to your buddy list Edit/Delete Message Reply w/Quote
niklasu
Junior Member

Registered: Jan 2007
From: Sweden

XPathNode and XPathAttribute

quote:
Originally posted by Instructor
Added: ${xml::XPathString} -compute a string XPath expression.
Added: ${xml::XPathNode} -compute a node XPath expression and goes to it.
Added: ${xml::XPathAttribute} -compute an attribute XPath expression and goes to it.



I'm trying to use XPathAttribute to change a setting in a web.config file, like this:
PHP:

${xml::LoadFile} "$INSTDIRWeb.config" $0
${xml::XPathAttribute} "/configuration/appSettings/add[@key='EPsConnection']" $0
${xml::SetAttribute} "value" "some value" $0
${xml::SaveFile} "$INSTDIRWeb.config" $0
${xml::Unload}


But everytime the xml:XPathAttribute statement executes the installer crashes with the following message:
code:
Microsoft Visual C++ Runtime Library Assertion failed! Program: setup.exe File: tinyxml.cpp Line: 173 Expression: node->GetDocument() == 0 || node->GetDocument() == this->GetDocument()

(And I get the same error when using XPathNode too...)
What am I doing wrong here?

Quick Link | Report this post to a moderator | IP: Logged

niklasu is offline Old Post 01-17-2007 07:47 PM
Click Here to See the Profile for niklasu Find more posts by niklasu Add niklasu to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

code:
${xml::LoadFile} "$INSTDIRWeb.config" $0 ${xml::RootElement} $0 $1 ${xml::XPathAttribute} "/configuration/appSettings/add[@key='EPsConnection']" $0 ${xml::SetAttribute} "value" "some value" $0 ${xml::SaveFile} "$INSTDIRWeb.config" $0 ${xml::Unload}

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 01-18-2007 09:38 PM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
Yathosho
Forum King

Registered: Jan 2002
From: AT-DE

could you put this on the wiki please?

__________________
Fossil 2002 III | VISBOT TV | NSIS Icons | PimpBot | Old Winamp Forums look?

Quick Link | Report this post to a moderator | IP: Logged

Yathosho is offline Old Post 02-03-2007 01:10 PM
Click Here to See the Profile for Yathosho Click here to Send Yathosho a Private Message Visit Yathosho's homepage! Find more posts by Yathosho Add Yathosho to your buddy list Edit/Delete Message Reply w/Quote
Commerzpunk
Junior Member

Registered: Feb 2007
From:

Thumbs up

quote:
Originally posted by Instructor
1. Not.
2. I'm not plaining this.

But you can use ${xml::CloneNode}

code:
Section ${xml::LoadFile} "file.xml" $0 MessageBox MB_OK "xml::LoadFile$\n$$0=$0" ${xml::GotoPath} "/" $0 MessageBox MB_OK "xml::GotoPath$\n$$0=$0" ${xml::CloneNode} $R0 MessageBox MB_OK "xml::CloneNode$\n$$R0=$R0" ${xml::Unload} ${xml::LoadFile} "file2.xml" $0 MessageBox MB_OK "xml::LoadFile$\n$$0=$0" ${xml::GotoPath} "/" $0 MessageBox MB_OK "xml::GotoPath$\n$$0=$0" ${xml::InsertBeforeNode} "$R0" $0 MessageBox MB_OK "xml::InsertBeforeNode$\n$$0=$0" ${xml::FreeNode} "$R0" $0 MessageBox MB_OK "xml::FreeNode$\n$$0=$0" ${xml::SaveFile} "file2.xml" $0 MessageBox MB_OK "xml::SaveFile$\n$$0=$0" ${xml::Unload} SectionEnd




I really tried hard to get this working for me.
The installer always crashed, when I tried to "InsertBeforeNode".

Now, I used this code and changed it, had several hundered crashes.

Here is the working result (for me):

code:
${xml::LoadFile} "file1.xml" $0 MessageBox MB_OK "xml::LoadFile$\n$$0=$0" ${xml::GotoPath} "Root/I" $0 MessageBox MB_OK "xml::GotoPath$\n$$0=$0" ${xml::CloneNode} $R0 MessageBox MB_OK "xml::CloneNode$\n$$R0=$R0" ${xml::LoadFile} "file2.xml" $0 MessageBox MB_OK "xml::LoadFile$\n$$0=$0" ${xml::RootElement} $0 $1 # THATS THE SOLUTION FOR NO CRASHING! MessageBox MB_OK "xml::RootElement$\n$$0=$0" MessageBox MB_OK "xml::RootElement$\n$$1=$1" ${xml::GotoPath} "I" $0 MessageBox MB_OK "xml::GotoPath$\n$$0=$0" ${xml::InsertBeforeNode} "$R0" $0 MessageBox MB_OK "xml::InsertBeforeNode$\n$$0=$0" ${xml::SaveFile} "file2.xml" $0 MessageBox MB_OK "xml::SaveFile$\n$$0=$0" ${xml::Unload}


Messageboxes are for information and debugging only, of course!

Greets,

HA

Last edited by Commerzpunk on 02-09-2007 at 10:14 AM

Quick Link | Report this post to a moderator | IP: Logged

Commerzpunk is offline Old Post 02-09-2007 09:53 AM
Click Here to See the Profile for Commerzpunk Click here to Send Commerzpunk a Private Message Click Here to Email Commerzpunk Find more posts by Commerzpunk Add Commerzpunk to your buddy list Edit/Delete Message Reply w/Quote
eafonsof
Junior Member

Registered: May 2007
From:

Modify "value" attribute.

Hi there, I tried the following commands to modify the attribute named "value". It's not working as I expected. Does anybody know what's missing or wrong?
Thanks in advance.

;Format of config file:
;<?xml version="1.0" encoding="Windows-1252"?>
;<configuration>
; <appSettings>
; <add key="key1" value="value1" />
; <add key="key2" value="value2" />
; <add key="key3" value="value3" />
;
; <!-- Some comments -->
; <add key="key4" value="value4" />
; </appSettings>
;</configuration>

${xml::LoadFile} "$configFile" $0
${xml::RootElement} $0 $1
${xml::XPathAttribute} "/configuration/appSettings/add[@key='${KEY4}']" $0
${xml::SetAttribute} "value" "$newValue" $0
${xml::SaveFile} "$configFile" $0
${xml::Unload}

After this, the attribute "value" is set as an attribute of "<configuration" instead of the corresponding "<add" node.

i.e.
;
;<?xml version="1.0" encoding="Windows-1252"?>
;<configuration value="new_value4">
; <appSettings>
; <add key="key1" value="value1" />
; <add key="key2" value="value2" />
; <add key="key3" value="value3" />
;
; <!-- Some comments -->
; <add key="key4" value="value4" />
; </appSettings>
;</configuration>

Quick Link | Report this post to a moderator | IP: Logged

eafonsof is offline Old Post 05-10-2007 07:31 PM
Click Here to See the Profile for eafonsof Click here to Send eafonsof a Private Message Find more posts by eafonsof Add eafonsof to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

code:
${xml::LoadFile} "$configFile" $0 ${xml::RootElement} $0 $1 ${xml::XPathNode} "/configuration/appSettings/add[@key='${KEY4}']" $0 ${xml::SetAttribute} "value" "$newValue" $0 ${xml::SaveFile} "$configFile" $0 ${xml::Unload}

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 05-18-2007 07:40 PM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

Updated: TinyXml to v2.5.3
Updated: TinyXPath to v1.3.0


"XML" plugin v1.9

Download from Wiki

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 06-01-2007 12:14 PM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
DrDan
Member

Registered: Apr 2007
From: London, UK

Question Question about the plugin

I'm working on an installer that uses this plug-in. Now, depending on the contents in my XML I need to run an external progam (in fact another NSIS uninstaller) that will read in the XML file and make changes to it.

The steps I am following are:

1) Open the XML file in the main installer
2) Manipulate as required
3) Determine if an external uninstaller is required
4) If an external uninstaller is required, then save the XML file, run the external uninstaller, re-load the XML file and carry on.
5) If no external uninstaller is required, carry on.

My question is, in step 4, should I also unload the XML plug-in (i.e. call ${xml::Unload}) before running the external uninstaller?

Thanks.

Quick Link | Report this post to a moderator | IP: Logged

DrDan is offline Old Post 07-04-2007 09:08 AM
Click Here to See the Profile for DrDan Click here to Send DrDan a Private Message Find more posts by DrDan Add DrDan to your buddy list Edit/Delete Message Reply w/Quote
Wizarth
Junior Member

Registered: Jul 2007
From:

SizeOf

Edit: Sorry, wrong thread.

Quick Link | Report this post to a moderator | IP: Logged

Wizarth is offline Old Post 07-10-2007 05:20 AM
Click Here to See the Profile for Wizarth Click here to Send Wizarth a Private Message Find more posts by Wizarth Add Wizarth to your buddy list Edit/Delete Message Reply w/Quote
walb07
Junior Member

Registered: Aug 2007
From:

Problem to parse XML with <!DOCTYPE ... []> element

Hi,

I've problems to parse an XML file which contains DTD description between xml header and first root element

Method ${xml::RootElement} returns with "-1". If I change the <!DOCTYPE ..[]> to a comment <!--DOCTYPE ...[]> which isn't really feasible it will work.

It would be helpful to support the DOCTYPE dtag by default.

example:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE RootElement [
<!ELEMENT RootElement (System+)>
<!ELEMENT System EMPTY>

<!ATTLIST RootElement Version CDATA #REQUIRED>
...
]>
<RootElement>
...
</RootElement>

with regards,
Dierk

Quick Link | Report this post to a moderator | IP: Logged

walb07 is offline Old Post 08-20-2007 09:46 AM
Click Here to See the Profile for walb07 Click here to Send walb07 a Private Message Find more posts by walb07 Add walb07 to your buddy list Edit/Delete Message Reply w/Quote
jogijhelumi
Junior Member

Registered: Jan 2008
From:

I'm trying to use XPathNode for expressions with namespace i.e. fns: Deployment
, but it fails and return error code -1.

Is there any trick/workaround to use it in this way.

Quick Link | Report this post to a moderator | IP: Logged

jogijhelumi is offline Old Post 01-22-2008 11:09 AM
Click Here to See the Profile for jogijhelumi Click here to Send jogijhelumi a Private Message Find more posts by jogijhelumi Add jogijhelumi to your buddy list Edit/Delete Message Reply w/Quote
FkYkko
Junior Member

Registered: Jan 2008
From:

Hi I'm wondering if the attached plugin in this thread is the latest version of this plugin? It seems to me that the include file (xml.nsh) differs from the source code regarding some functions? For example, RemoveChild seems to return an error code while the include file and documentation does not specify any variable for this method. The RemoveAllChild function is not implemented in the source but is is availible in the documentation and include file?
Are there any updates regarding this? Maybe set up a simple sourceforge page to be able to update it?

or is there some other XML plugin which is generally used and better supported?

p.s. jogijhelumi: URL submitted by user. says that namespaces are not supported yet d.s.

Last edited by FkYkko on 01-29-2008 at 04:40 PM

Quick Link | Report this post to a moderator | IP: Logged

FkYkko is offline Old Post 01-29-2008 04:24 PM
Click Here to See the Profile for FkYkko Click here to Send FkYkko a Private Message Find more posts by FkYkko Add FkYkko to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

Updated: TinyXPath to v1.3.1

Fixed: missing "xml::_RemoveAllChild" in DLL.
Fixed: ${xml::RemoveNode} incorrectly documented.


"XML" plugin v2.0

Download from Wiki

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 01-30-2008 03:31 PM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
FkYkko
Junior Member

Registered: Jan 2008
From:

Thanks for the quick reply.
As it happens, I still have some problems with this plugin and have changed to nsisXML (by W) which works after some rewrites.

Quick Link | Report this post to a moderator | IP: Logged

FkYkko is offline Old Post 01-31-2008 08:01 AM
Click Here to See the Profile for FkYkko Click here to Send FkYkko a Private Message Find more posts by FkYkko Add FkYkko to your buddy list Edit/Delete Message Reply w/Quote
Tzzz
Junior Member

Registered: Mar 2008
From: France

XML::Xxxx functions: doc to improve

Hello,

It seems to have ben many misunderstanding since the new XML::Xxxx functions were launched:

quote:

Added: ${xml::XPathString} -compute a string XPath expression.
Added: ${xml::XPathNode} -compute a node XPath expression and goes to it.
Added: ${xml::XPathAttribute} -compute an attribute XPath expression and goes to it.



I think that Instructor could get rid of most of them by improving the examples from its documentation:
In particular :
- Use of ${xml::RootElement} $0 $1 seems to fix many issues; please comment its use in XML::XPathNode, XML::XPathAttribute and XML::XPathString functions documentation whenever needed.
- Use of ${xml::XPathNode} "/configuration/components/component[@id='applicationSettings.default']/parameters/dbServerName" $0 is badly documented, i.e.:
. - XPath expression (e.g. "/a/b/@attr") is documented only for ${xml::XPathAttribute}, not for ${xml::XPathNode} whereas it seems to be afix for many cases.
. - Why is it that one shall use ${xml::XPathnode} prior to use a ${xml::SetAttribute} while logic would say to better use ${xml::XPathAttribute} instead. Instructor provides this kind of fixing but never fully explains why it is this way. Either fix ${xml::XPathAttribute} so that it allows to do what users think it should do, either fix the documentation so that its use is clearer compared to ${xml::XPathNode}.

Thank you very much for your plugin.

Quick Link | Report this post to a moderator | IP: Logged

Tzzz is offline Old Post 03-21-2008 03:38 PM
Click Here to See the Profile for Tzzz Find more posts by Tzzz Add Tzzz to your buddy list Edit/Delete Message Reply w/Quote
xbarns
Senior Member

Registered: Aug 2007
From: Frankfurt, Germany

Hi all,

i need to edit a xml structure like this

PHP:

<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 FilesTestDatabaseTest.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:

PHP:

${xml::LoadFile} "$EXEDIRscMaster.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} "$EXEDIRscMaster2.ctf" $0
${xml::Unload}




Thanks for helping

Quick Link | Report this post to a moderator | IP: Logged

xbarns is offline Old Post 03-26-2008 11:48 AM
Click Here to See the Profile for xbarns Click here to Send xbarns a Private Message Find more posts by xbarns Add xbarns to your buddy list Edit/Delete Message Reply w/Quote
freeDB_man
Junior Member

Registered: Jan 2008
From:

I tried to use this plug-in with the special build of NSIS that has a string length limitation of 8192 instead of 1024 but the plug-in is indifferent to the change and only reads 1024 chars.

Any workaround?

Quick Link | Report this post to a moderator | IP: Logged

freeDB_man is offline Old Post 04-26-2008 01:05 PM
Click Here to See the Profile for freeDB_man Click here to Send freeDB_man a Private Message Click Here to Email freeDB_man Find more posts by freeDB_man Add freeDB_man to your buddy list Edit/Delete Message Reply w/Quote
spitze
Junior Member

Registered: May 2008
From: Ingolstadt

Hi all,
first of all great plugin. But i have a problem which i cannot solve.
I want to insert a line in an XML file.

The XML file looks like:


PHP:

<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<adtf:configuration xmlns:adtv="adtv">
    <general_settings>
        <property name="gui_refresh_rate" value="25"/>
    </general_settings>
    <module_directories>
    </module_directories>
    <template_directories/>
</adtf:configuration>



Now i want to insert:

PHP:

<directory path="C:program filesTest"/>



between

PHP:

<module_directories>
</
module_directories>




I tried this piece of code

PHP:

${xml::FindNextElement} "module_directories" $0 $1
${xml::CreateNode} '<directory path="C:program filesTest"/>' $4
${xml::InsertAfterNode} $4 $5



The Output is:

PHP:

<module_directories />
<
directory path="C:program filesTest"/>



but it should be:

PHP:

<module_directories>
  <
directory path="C:program filesTest"/>
</
module_directories>



Any suggestions??
Thanx

Quick Link | Report this post to a moderator | IP: Logged

spitze is offline Old Post 06-11-2008 07:46 AM
Click Here to See the Profile for spitze Click here to Send spitze a Private Message Find more posts by spitze Add spitze to your buddy list Edit/Delete Message Reply w/Quote
Instructor
Major Dude

Registered: Jul 2004
From:

code:
${xml::FindNextElement} "module_directories" $0 $1 ${xml::CreateNode} '<directory path="Crogram filesTest"/>' $4 ${xml::InsertEndChild} $4 $5

__________________
my functions

Quick Link | Report this post to a moderator | IP: Logged

Instructor is offline Old Post 06-11-2008 09:28 AM
Click Here to See the Profile for Instructor Click here to Send Instructor a Private Message Click Here to Email Instructor Visit Instructor's homepage! Find more posts by Instructor Add Instructor to your buddy list Edit/Delete Message Reply w/Quote
radorl
Junior Member

Registered: Dec 2008
From:

I'm editing XML file which uses &#DDDD; notation for non-ASCII characters. I noticed that after saving of modified XML file all &#DDDD; characters were replaced by original two-byte UTF-8 codes.

Is there some way how to instruct this wonderful plugin to use &#DDDD; notation?

Quick Link | Report this post to a moderator | IP: Logged

radorl is offline Old Post 12-27-2008 12:11 PM
Click Here to See the Profile for radorl Click here to Send radorl a Private Message Click Here to Email radorl Find more posts by radorl Add radorl to your buddy list Edit/Delete Message Reply w/Quote
casioclave
Junior Member

Registered: Mar 2009
From:

Question need some help

Hi. Can U help me to change value in this stiring <value>en</value> from "en" to "ru"

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="inVisit.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="inVisit.Properties.Settings.ivConnection" connectionString="Data Source=.\sqlexpress;AttachDbFilename=;Initial Catalog=ivData;Integrated Security=True;Connect Timeout=30"
providerName="" />
</connectionStrings>
<userSettings>
<inVisit.Properties.Settings>
<setting name="WinFormState" serializeAs="String">
<value>Normal</value>
</setting>
<setting name="WinFormSize" serializeAs="String">
<value>800, 600</value>
</setting>
...
<setting name="Language" serializeAs="String">
<value>en</value>
</setting>
<setting name="AutoCheckOut" serializeAs="String">
<value>False</value>
</setting>

</userSettings>
</configuration>

Last edited by casioclave on 03-20-2009 at 10:36 AM

Quick Link | Report this post to a moderator | IP: Logged

casioclave is offline Old Post 03-20-2009 07:36 AM
Click Here to See the Profile for casioclave Click here to Send casioclave a Private Message Click Here to Email casioclave Find more posts by casioclave Add casioclave to your buddy list Edit/Delete Message Reply w/Quote
mattm591
Junior Member

Registered: May 2009
From:

I am trying to use this plugin to get values from an XML structure.

The document looks something like this:

<xml>
<groups>
<group id="1">
<name>Group 1</name>
</group>
<group id="2">
<name>Group 2</name>
</group>
<group id="3">
<name>Group 3</name>
</group>
</groups>
</xml>

I want to get the values of id and name and am currently working on getting value. After loading the document I can get the value of the first group (id 1) by doing this,

PHP:

${xml::GotoPath} "/xml/groups/group" $0
${xml::GetAttribute} "id" $0 $1


but I cannot get any others.

The code I am trying uses {xml::NextAttribute} and no matter what I do I alway get -1 returned for $2 and $0 and $1 are null. I originally tried it like this to get the loop, but it doesn't work even if I only run it once.
PHP:

${xml::NextAttribute} $0 $1 $2
${While} $2 != -1
  
${xml::NextAttribute} $0 $1 $2
  MessageBox MB_OK
$0
${EndWhile}



Can anyone please tell me what I'm doing wrong and how I can access these values.

Quick Link | Report this post to a moderator | IP: Logged

mattm591 is offline Old Post 05-26-2009 02:03 PM
Click Here to See the Profile for mattm591 Find more posts by mattm591 Add mattm591 to your buddy list Edit/Delete Message Reply w/Quote
mattm591
Junior Member

Registered: May 2009
From:

Ok I have managed to get it working.

For anyone else with a similar issue here is what I did. (I used LastChild and PreviousSibling because I wanted to get the xml in reverse, replace with FirstChild and NextSibling to go through in order). Also, I make use of LogicLib which you will need to include if you're copying this example.

PHP:

${xml::GotoPath} "/xml/groups" $0
${xml::LastChild} "group" $1 $0

${While} $0 == 0

  
#get the group id
  
${xml::GetAttribute} "id" $1 $3

  
#get the group name
  
${xml::FirstChildElement} "name" $3 $4
  
${xml::GetText} $2 $3

  
#move to next group
  
${xml::Parent} $3 $4
  
${xml::PreviousSibling} "group" $1 $0

${EndWhile}

Quick Link | Report this post to a moderator | IP: Logged

mattm591 is offline Old Post 05-27-2009 02:37 PM
Click Here to See the Profile for mattm591 Find more posts by mattm591 Add mattm591 to your buddy list Edit/Delete Message Reply w/Quote
sag47
Junior Member

Registered: Dec 2006
From:

Here is a nice small example of using this plugin. In my installer header I included XML.nsh.

code:
include "XML.nsh"


Here is a sample XML file that you should extract to the temp folder ($TEMP).

code:
<?xml version='1.0' encoding='UTF-8' ?> <account version='1.0'> <account> <protocol>prpl-jabber</protocol> <name></name> <settings> <setting name='use-global-buddyicon' type='bool'>1</setting> <setting name='require_tls' type='bool'>1</setting> <setting name='ft_proxies' type='string'>gtalk.google.com:7777</setting> <setting name='check-mail' type='bool'>0</setting> <setting name='connect_server' type='string'>gtalk.google.com</setting> <setting name='old_ssl' type='bool'>0</setting> <setting name='auth_plain_in_clear' type='bool'>0</setting> <setting name='buddy_icon_timestamp' type='int'>0</setting> <setting name='port' type='int'>443</setting> <setting name='custom_smileys' type='bool'>1</setting> </settings> <settings ui='gtk-gaim'> <setting name='auto-login' type='bool'>1</setting> </settings> </account> </account>


Basically what I wanted to do in the XML file above was to set text inside of the <name></name> XML node to text that is dependent on user options in my installer. Here's my NSIS code that I use to modify the above XML:
PHP:

${xml::LoadFile} "$TEMP\accounts.xml" $0
  IntCmp
$0 0 +2 +1 +2
  MessageBox MB_OK
|MB_ICONSTOP "Error loading accounts.xml!"
  
${xml::RootElement} $1 $0
  
${xml::FirstChildElement} "" $1 $0
  
${xml::FirstChildElement} "name" $1 $0
  DetailPrint
"Setting sam@gtalk.google.com/Home"
  
${xml::SetText} "sam@gtalk.google.com/Home" $0
  IntCmp
$0 0 +2 +1 +2
  MessageBox MB_OK
|MB_ICONSTOP "Error setting username!"
  
${xml::SaveFile} "" $0
  IntCmp
$0 0 +2 +1 +2
  MessageBox MB_OK
|MB_ICONSTOP "Error saving accounts.xml!"
  
${xml::Unload}



Commands above explained...

  1. ${xml::LoadFile} "$TEMP\accounts.xml" $0 loads my XML file to be modified.
  2. ${xml::RootElement} $1 $0 selects the root node <account version='1.0'>
  3. ${xml::FirstChildElement} "" $1 $0 selects the first childnode located in the root node (which happens to be <account> ). No argument means select the first childnode no matter what its name is.
  4. ${xml::FirstChildElement} "name" $1 $0 selects the first childnode within the node accounts > accounts that has the name "name" or <name></name>.
  5. ${xml::SetText} "sam@gtalk.google.com/Home" $0 sets the text inside of <name></name> so the result is <name>sam@gtalk.google.com/Home</name>
  6. ${xml::SaveFile} "" $0 saves changes that I've made to my XML file. No argument means save to the same file that was originally opened
  7. ${xml::Unload} unloads the XML plugin since I'm done modifying my XML file.
  8. If you're wondering about IntCmp $0 0 +2 +1 +2, $0 is the error code returned by the given XML command. IntCmp compares the integer variable $0 with the integer 0 (zero). If $0 is equal to 0 then go down +2 commands (skipping the error message). If $0 is less than 0 then go down +1 command (show the error message). If $0 is greater than 0 then go down +2 commands (skip the error message). Skipping commands like that ignores comments.


Here is what my XML file looks like after being modified...
code:
<?xml version='1.0' encoding='UTF-8' ?> <account version='1.0'> <account> <protocol>prpl-jabber</protocol> <name>sam@gtalk.google.com/Home</name> <settings> <setting name='use-global-buddyicon' type='bool'>1</setting> <setting name='require_tls' type='bool'>1</setting> <setting name='ft_proxies' type='string'>gtalk.google.com:7777</setting> <setting name='check-mail' type='bool'>0</setting> <setting name='connect_server' type='string'>gtalk.google.com</setting> <setting name='old_ssl' type='bool'>0</setting> <setting name='auth_plain_in_clear' type='bool'>0</setting> <setting name='buddy_icon_timestamp' type='int'>0</setting> <setting name='port' type='int'>443</setting> <setting name='custom_smileys' type='bool'>1</setting> </settings> <settings ui='gtk-gaim'> <setting name='auto-login' type='bool'>1</setting> </settings> </account> </account>


Note: I changed XML values from my actual installer for the sake of this quick example to help get others started. So I would ignore the actual content because it has no use at all.

It took only a couple of minutes of reading the documentation that came with the XML plugin for NSIS that I created the above functions. So read the documentation for a better explanation of all of the capabilities possible with this wonderful plugin.

Sam Gleske

Last edited by sag47 on 10-18-2009 at 10:52 PM

Quick Link | Report this post to a moderator | IP: Logged

sag47 is offline Old Post 10-18-2009 10:26 PM
Click Here to See the Profile for sag47 Click here to Send sag47 a Private Message Click Here to Email sag47 Find more posts by sag47 Add sag47 to your buddy list Edit/Delete Message Reply w/Quote
ChocJunkie
Member

Registered: Oct 2009
From: Germany

What's the difference between using

code:
${FirstChildElement} "name" $var1 $var2
and
code:
${FirstChild} "name" $var1 $var2
for getting a element child? Especially, I'm interested what ${FirstChildElement} exists for, if the task can be done using ${FistChild}. A child can only be of type text or element. So that ${FirstChild} "Name" does search for a element child, doesn't it?

Thanks

CJ

Quick Link | Report this post to a moderator | IP: Logged

ChocJunkie is offline Old Post 11-09-2009 10:31 AM
Click Here to See the Profile for ChocJunkie Click here to Send ChocJunkie a Private Message Find more posts by ChocJunkie Add ChocJunkie to your buddy list Edit/Delete Message Reply w/Quote
All times are GMT. The time now is 02:18 AM. Post New Thread    Post A Reply
Pages (2): « 1 [2]   Last Thread   Next Thread
WINAMP.COM | Forums : Powered by vBulletin version 2.3.9 WINAMP.COM | Forums > Developer Center > NSIS Discussion > XML plugin
Show Printable Version
 | 
Email this Page
 | 
Subscribe to this Thread

Forum Jump:
 

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is off
vB code is ON
Smilies are ON
[IMG] code is ON