如何在NSIS中创建结构数组
我有一个XML文件…现在我想解析它,并根据我在NSIS脚本中的要求将数据存储到结构数组中如何在NSIS中创建结构数组,nsis,Nsis,我有一个XML文件…现在我想解析它,并根据我在NSIS脚本中的要求将数据存储到结构数组中 This is my XML:- <?xml version="1.0" ?> - <request> - <software> <id>1</id> <name>software</name> <description>is a file archiver with a high c
This is my XML:-
<?xml version="1.0" ?>
- <request>
- <software>
<id>1</id>
<name>software</name>
<description>is a file archiver with a high compression ratio.</description>
<download_url>http://surfnet.dl.sourceforge.net/project/sevenzip/7-Zip/9.20/7z920.exe</download_url>
<image_url>http://assets.airinstaller.com/graphics/software/7zip/left_side.bmp</image_url>
</software>
- <offers>
- <offer>
<rank>1</rank>
- <options>
- <option>
<text>Install Facemoods1</text>
<value>/TOOLBAR</value>
<required>true</required>
</option>
- <option>
<text>Set Facemoods as my default search provider1</text>
<value>/DEFAULTSEARCH</value>
<required>false</required>
</option>
</options>
<install_location>{pf}/IssPro c.dll</install_location>
<name>1</name>
<tagline>The Ringtone Maker</tagline>
<description>makes creating ringtones really easy.</description>
<exe_cmd />
<download_url>http://174.36.153.163/silent-ringtonejunkiez-installer.exe</download_url>
<conversion_url>http://api.airinstaller.com/get/installed.php?session=9649922a0d879d92752f3925e07153c3&app=2&aff=1&off=1</conversion_url>
<image_url>http://assets.airinstaller.com/graphics/offers/ringtonejunkiez/logo.bmp</image_url>
<privacy_url>http://www.google.com/intl/en/privacy/privacy-policy.html</privacy_url>
<terms_url>http://www.google.com/accounts/TOS</terms_url>
</offer>
- <offer>
<rank>2</rank>
- <options>
- <option>
<text>Install Facemoods</text>
<value>/TOOLBAR</value>
<required>true</required>
</option>
- <option>
<text>Set Facemoods as my default search provider</text>
<value>/DEFAULTSEARCH</value>
<required>false</required>
</option>
- <option>
<text>Set Facemoods as my default home and new tab page</text>
<value>/DEFAULTSTART</value>
<required>false</required>
</option>
</options>
<name>Ringtone 2</name>
<tagline>The Ringtone Maker</tagline>
<description>makes creating ringtones really easy.</description>
<exe_cmd />
<download_url>http://174.36.153.163/silent-ringtonejunkiez-installer.exe</download_url>
<conversion_url>http://api.airinstaller.com/get/installed.php?session=9649922a0d879d92752f3925e07153c3&app=2&aff=1&off=1</conversion_url>
<image_url>http://assets.airinstaller.com/graphics/offers/ringtonejunkiez/logo.bmp</image_url>
<privacy_url>http://www.google.com/intl/en/privacy/privacy-policy.html</privacy_url>
<terms_url>http://www.google.com/accounts/TOS</terms_url>
</offer>
- <offer>
<rank>3</rank>
<id>13</id>
<install_location>{pf}/Real/RealPlayer/f ixrjb.exe</install_location>
<name>3</name>
<description>makes creating ringtones really easy.</description>
<exe_cmd />
<download_url>http://174.36.153.163/silent-ringtonejunkiez-installer.exe</download_url>
<conversion_url>http://api.airinstaller.com/get/installed.php?session=9649922a0d879d92752f3925e07153c3&app=2&aff=1&off=1</conversion_url>
<image_url>http://assets.airinstaller.com/graphics/offers/ringtonejunkiez/logo.bmp</image_url>
<privacy_url>http://www.google.com/intl/en/privacy/privacy-policy.html</privacy_url>
<terms_url>http://www.google.com/accounts/TOS</terms_url>
</offer>
</offers>
</request>
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
现在我希望将数据存储到结构数组中,而不是简单的数组中……因为XML是动态的,并且大小(标记)可以增加,所以我认为将数据存储到结构数组(而不是单独的数组)中会更好 NSIS没有对数组的本机支持,但您可以使用列出的备选方案之一。首先,您需要使用一些XML插件(如下所示)从XML解析数据
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
然后使用一些插件将数据保存在阵列中(建议使用nsArray插件)
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
是否要在数组中保存整棵树?我认为这是一项非常艰巨的任务,因为有很多可能性:您想保存所有元素还是只保存非空元素?
或者您只是想读取一些值
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
请更具体地说明阵列的外观
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
编辑:(示例)
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
只需在循环中遍历加载的树并保存数据:
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}
IntOp $R1 0 + 0 ; Set $R1 to zero at beginning
${While} End_Of_XML_Tree
; Fill $your_value with the data you want (element name, value or even whole node path)
nsArray::Set your_array /key=$R1 $your_value ; Save value to your_array at key = $R1
IntOp $R1 $R1 + 1 ; Increase $R1 (next key)
${EndWhile}
nsArray::Set在
键处添加值
,用该键替换任何现有值。谢谢回复……但我的问题是如何生成结构数组,然后将整个XML数据存储到其中……我已经使用XML插件解析了它,现在我需要将整个数据存储到结构数组中……谢谢回复……但我的问题是如何生成结构数组,然后将整个XML数据存储到其中……为什么需要存储XML?先假设你没有。你想从中得到什么?你打算用它做什么?为什么是XML?(你能把它做成像INI这样易于使用的格式吗?)!你还不需要知道。首先,解释你为什么需要它。我不相信你真的需要它:另一种访问它的方式可能会更好。把重点放在问题上,而不是你想解决它的方法上,这在NSIS中是不可能的。我想知道我们能不能像在c/c++中那样在NSIS中生成结构数组。如果是,那么我们如何才能做到?你问的问题不对。请重新阅读我之前的两条评论。我正在制作动态安装程序,其中首先它向URL发送请求,URL从那里发回XML作为响应。我必须获取数据并存储,然后我必须在自定义页面上逐个显示数据,就像提供标签一样,在一个页面上仅显示一个提供……。因此,问题是如何解决为了存储数据以便以后可以方便地使用,还有一个问题是,我们不知道XML中提供标记的数量,它们可以是2个或5个,也可以是10个……那么存储数据的更好方法是什么呢???
${XML::GotoPath} "/request/software" $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Next Sibling Element of Root Element=$0" ; SIBLING OF SOFTWARE (SECOND CHILD OF ROOT)
${XML::XPathString} "count(//offer)" $0 $1
StrCpy $ccount_offer $0
;${If} $0 != ""
; IntOp $count_offer $count_offer + 1
; DetailPrint "Count= $0 and $count_offer"
;Goto for
;${Else}
;Goto next
;${EndIf}
${For} $R1 1 $ccount_offer
${If} $R1 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Offers=$0" ; FIRST ElEMENT IN OFFERS
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in offer=$0"
${xml::ElementPath} $0
StrCpy $ccurrent_path $0
${EndIf}
${XML::XPathString} "count(child::*)" $0 $1
;DetailPrint "count======$0"
StrCpy $ccount_offer_child $0
${XML::FirstChildElement} "" $0 $1 ;first child of offer
DetailPrint "Element in Offer=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
IntOp $ccount_offer_child $ccount_offer_child - 1
${For} $R2 1 $ccount_offer_child
;${If} $R2 == 1
;${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Offer=$0"
${If} $0 == "options" ; options for loops
${xml::ElementPath} $0
StrCpy $llast_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options $0
${If} $0 != 0
${For} $R3 1 $ccount_options
${If} $R3 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Options=$0"
${xml::ElementPath} $0
StrCpy $llast_last_current_path $0
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${XML::GotoPath} $llast_last_current_path $0
${Else}
${XML::GotoPath} $llast_last_current_path $0
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Options=$0"
${XML::XPathString} "count(child::*)" $0 $1
StrCpy $ccount_options_option $0
${For} $R4 1 $ccount_options_option
${If} $R4 == 1
${XML::FirstChildElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${Else}
${XML::NextSiblingElement} "" $0 $1
DetailPrint "Element in Option=$0"
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
${Next}
${EndIf}
${Next}
${EndIf}
${XML::GotoPath} $llast_current_path $0 ;end of options for loops
${ElseIf} $0 == "exe_cmd"
${Else}
${XML::GetText} $0 $1
DetailPrint "Text in it=$0"
${EndIf}
; ${EndIf}
${Next}
${XML::GotoPath} "$ccurrent_path" $0
${Next}