我有一个 XML 文件....现在我想根据我在 NSIS SCRIPT 中的要求解析它并将数据存储到结构数组中。
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>
请任何人帮助我解析它并存储到 NSIS 脚本中的结构数组中......
我被严重困在这里......
感谢您的回复,但我没有得到这个.......
我已经用这个方法解析了 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}
现在我希望将数据存储到结构数组中而不是简单的数组中......因为 XML 是动态的并且大小(标签)可以增加所以我认为将数据存储到结构数组中(不单独数组)将是更好的方法.....