I am trying to read a root attribute, but still do not manage to do it using wizous xml.nsh plugin :(
Code itself is straight forward:
${xml::LoadFile} "${WHICH_DIR}" $0
${xml::RootElement} $R1 $R0
!ifdef DEBUGMODE_NSISDBG
nsisdbg::sendtolog /NOUNLOAD " root : $R1"
!endif
${xml::GotoPath} "${XML_PATH}" $R1
!ifdef DEBUGMODE_NSISDBG
nsisdbg::sendtolog /NOUNLOAD "GotoPath '${XML_PATH}' result: $R1 "
!endif
${xml::GetAttribute} "${XML_PARAM}" "${XML_VARIABLE}" $R1
!ifdef DEBUGMODE_NSISDBG
nsisdbg::sendtolog /NOUNLOAD "GetAttribute '${XML_PARAM}' result '$R1' : ${XML_VARIABLE} "
${xml::SetAttribute} "port" "$EditTextEditText" $0
${xml::SaveFile} "agent.xml" $0
${xml::Unload}
But the output still is not what I need:
<2012.04.17. 13:01:04> root : agent
<2012.04.17. 13:01:04> GotoPath '/agent/' result: -1
<2012.04.17. 13:01:04> GetAttribute 'port' result '0' :
The input XML file:
<?xml version="1.0" encoding="windows-1257"?>
<agent port="0000" loglevel="3">
</agent>
Thank you for any tip or kind of help.
Some preliminary points :
While working on your sample I noticed that
GetAttribute
expects a variable as 2nd parameter to store the resultGotoPath
does not work with a final /
I have the expected result by removing itOutputDebugString
messages!include "XML.nsh"
Name "Sample nsisXML"
OutFile "SampleSO.exe"
ShowInstDetails show
!define XML_PATH "/agent"
!define XML_PARAM "port"
var XML_VARIABLE
!define DEBUG `System::Call kernel32::OutputDebugString(ts)`
!macro GetXMLParam PATH PARAM VARIABLE
${xml::GotoPath} "${PATH}" $R1
${DEBUG} "GotoPath '${PATH}' result: $R1 "
${xml::GetAttribute} "${PARAM}" ${VARIABLE} $R1
${DEBUG} "GetAttribute '${PARAM}' result '$R1' : ${VARIABLE} "
!macroend
Section "Main program"
${xml::LoadFile} "so.xml" $0
${xml::RootElement} $R1 $R0
${DEBUG} " root : $R1"
!insertmacro GetXMLParam "/agent" "port" $XML_VARIABLE
; ${xml::GotoPath} "${XML_PATH}" $R1
; ${DEBUG} "GotoPath '${XML_PATH}' result: $R1 "
; ${xml::GetAttribute} "${XML_PARAM}" $XML_VARIABLE $R1
; ${DEBUG} "GetAttribute '${XML_PARAM}' result '$R1' : $XML_VARIABLE "
${xml::SetAttribute} "port" "$XML_VARIABLE" $0
${xml::SaveFile} "agent.xml" $0
${xml::Unload}
SectionEnd
Result :
root : agent
GotoPath '/agent' result: 0
GetAttribute 'port' result '0' : 0000