Installation 如果特定元素在xml中为空,则无法使用NSIS安装程序更新该元素的值

Installation 如果特定元素在xml中为空,则无法使用NSIS安装程序更新该元素的值,installation,nsis,Installation,Nsis,我正在编写NSIS[Nullsoft安装程序系统]安装程序脚本。例如,当元素为空时,我面临更新XML元素值[使用的XML插件]的问题 **Element value to be updated: <Name /> After executing the below script, the output is : <Test />** ${xml::LoadFile} "$EXEDIR\install1.config" $0 ${If} $0 != -1 ${xml:

我正在编写NSIS[Nullsoft安装程序系统]安装程序脚本。例如,当元素为空时,我面临更新XML元素值[使用的XML插件]的问题

**Element value to be updated: <Name />
After executing the below script, the output is : <Test />**

${xml::LoadFile} "$EXEDIR\install1.config" $0
${If} $0 != -1
  ${xml::GotoPath} "/InstallerInputs/Name" $0
  ${xml::FirstChild} "" $0 $1
  ${xml::SetNodeValue} "Test"
  ${xml::SaveFile} "$EXEDIR\install1.config" $0
  ${xml::Unload}
  ${EndIf}
XML结构如下所示

<?xml version="1.0" encoding="utf-16" ?>
<InstallerInputs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   **<Name></Name>** or **<Name />**
   <Password></Password>
</InstallerInputs>
输出XML:

<?xml version="1.0" encoding="utf-16" ?>
<InstallerInputs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   **<Test/>**
   <Password></Password>
</InstallerInputs>
任何帮助…

两个问题:

GotoPath之后,您已经在正确的节点上,${xml::FirstChild}将失败,因为Name没有子节点。 ${xml::SetNodeValue}似乎设置了标记名,而不是内部文本。 试试这个

!if 0
FileOpen $0 "$Temp\test.xml" w
FileWrite $0 '<?xml version="1.0" encoding="utf-16" ?>$\r$\n'
FileWrite $0 '<InstallerInputs xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">$\r$\n'
FileWrite $0 '<Name></Name>$\r$\n'
FileWrite $0 '<Password></Password>$\r$\n'
FileWrite $0 '</InstallerInputs>$\r$\n'
FileClose $0
!endif

${xml::LoadFile} "$Temp\test.xml" $0
${If} $0 != -1
    ${xml::GotoPath} "/InstallerInputs/Name" $0
    ${If} $0 = 0
        ${xml::SetText}  "Test" $0
        ${xml::SaveFile} "$Temp\test.xml" $0
    ${EndIf}
    ${xml::Unload}
${EndIf}

${xml::GotoPath}/InstallerInputs/Name$0${xml::FirstChild}$0$1->如果FirstChild方法中的值为空,它将返回第一个创建的即Name元素。SetNodeValue->设置当前节点的值。实际上,当tes元素不为空时,元素值gest已更新。无论如何,感谢您指向使用SetText方法。它现在起作用了