我正在尝试读取root属性,但仍然无法使用wizous xml.nsh插件执行此操作:(
代码本身很简单:
${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}
但输出仍然不是我需要的:
<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' :
输入XML文件:
<?xml version="1.0" encoding="windows-1257"?>
<agent port="0000" loglevel="3">
</agent>
感谢您提供任何帮助。
答案 0 :(得分:0)
一些初步观点:
在处理您的样本时,我注意到了
GetAttribute
期望变量作为第二个参数来存储结果GotoPath
不适用于最终/
我通过删除它获得了预期的结果OutputDebugString
消息!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
结果:
root : agent
GotoPath '/agent' result: 0
GetAttribute 'port' result '0' : 0000