【发布时间】:2014-06-20 08:26:53
【问题描述】:
我有以下类型的 XML 文件:
<ECSC>
<ATTRIBUTES>
< all child nodes of attribute tag >
</ATTRIBUTES>
<SCRIPT>
<ETXML_LINE_TABTYPE>
<item>MESSAGE ( MSG_1 ).</item>
<item>* To get the name of the Title Screen.</item>
<item> GETGUI ( FB01_100_STEP_1 ).</item>
<item> SAPGUI ( FB01_100_STEP_2 ).</item>
<item>* Enter Amount and Tax Code.</item>
<item>* and, Press F4 help in the Order Field.</item>
<item> SAPGUI ( FB01_300_STEP_1 ).</item>
<item>* In F4 screen, enter the 'External Order Number'</item>
<item>* pop-up screen is displayed with entries like Order, Description and External Order Number and select 1st order row, press Enter.</item>
<item> SAPGUI ( FB01_200_STEP_1 ).</item>
<item>* To get the values for the field 'Order, Description and External Order No' from F4 help.</item>
<item> GETGUI ( FB01_120_STEP_1 ).</item>
<item>* Press 'Enter' button.</item>
<item> SAPGUI ( FB01_120_STEP_3 ).</item>
<item>* To get the value for the field 'Order' from Main screen.</item>
<item> GETGUI ( FB01_300_STEP_2 ).</item>
<item>* click on 'F3' back button.</item>
<item> SAPGUI ( FB01_300_STEP_3 ).</item>
<item>* click on 'F3' back button.</item>
<item> SAPGUI ( FB01_700_STEP_1 ).</item>
<item>* click 'Yes' button.</item>
<item> SAPGUI ( FB01_200_STEP_2 ).</item>
<item>* click on 'F3' back button.</item>
<item> SAPGUI ( FB01_100_STEP_3 ).</item>
<item>ENDMESSAGE ( E_MSG_1 ).</item>
<item/>
<item>* To display the Title Screen.</item>
<item> LOG ( V_TITLE_SCREEN ).</item>
<item>* To display the 'Order' Number from F4 help.</item>
<item> LOG ( V_ORDER_NO_FROM_F4 ).</item>
<item>* To display the 'Description' from F4 help.</item>
<item> LOG ( V_DESCRIPTION_FROM_F4).</item>
<item>* To display the 'External Order no' value from F4 help.</item>
<item> LOG ( V_EXTERNAL_ORDER_NO_FROM_F4 ).</item>
<item>* To display the 'Order' Number from main screen.</item>
<item> LOG ( V_ORDER_NO_FRM_MAIN_SCREEN ).</item>
<item>*********************************************************************.</item>
<item>* End Execution.</item>
<item>*********************************************************************.</item>
<item/>
<item>*******************************************************************.</item>
<item>* Check.</item>
<item>********************************************************************.</item>
<item>* To check name of Title screen for transaction FB01.</item>
<item> CHEVAR ( V_TITLE_SCREEN = I_TITLE_SCREEN ).</item>
<item>* To check the value for the field 'External Order No' from F4 help, which should be equal to 'External Order No' from table.</item>
<item> CHEVAR ( V_EXTERNAL_ORDER_NO_FRM_TABL = V_EXTERNAL_ORDER_NO_FROM_F4 ).</item>
<item>* To check the values for the field 'Order' number from Table, which should be equal to 'Order' no from F4 screen and Main screen.</item>
<item> CHEVAR ( ( I_ORDER_NUMBER_FROM_TABLE = V_ORDER_NO_FROM_F4 ) AND ( I_ORDER_NUMBER_FROM_TABLE = V_ORDER_NO_FRM_MAIN_SCREEN )).</item>
<item>*******************************************************************.</item>
<item>* End Check.</item>
<item>********************************************************************.</item>
</ETXML_LINE_TABTYPE>
</SCRIPT>
<PARAMETERS>
<all childnodes of parameter of parameters tag >
</PARAMETERS>
</ECSC>
我们想从上面的 XML 中选择一个特定的节点,如 <SCRIPT> 及其所有子节点,如所有 <item> 节点;我们想检测这样的 nodeText 没有提到任何评论。注释由从字符* 开始的行表示,并且每个注释行都出现在代码行的正上方;例如在上面的 XML 文件中,行:<item> SAPGUI ( FB01_100_STEP_2 ).</item> 没有任何注释,所以这是一个缺陷,我尝试了以下 vbscript。
Dim sFSpec : sFSpec = "D:\new Automation\backup\script.xml"
Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument")
objMSXML.setProperty "SelectionLanguage", "XPath"
objMSXML.async = False
objMSXML.load sFSpec
If 0 = objMSXML.parseError Then
Dim bCmnt : bCmnt = False
Dim ndItem
For Each ndItem In objMSXML.documentElement.childNodes
Dim sItem : sItem = ndItem.text
If "*" = Left(sItem, 1) Then
bCmnt = True
Else
If Not bCmnt Then
If "" <> sItem And 0 = Instr(sItem, "MESSAGE") Then
msgbox "no comment for:", sItem
End If
End If
bCmnt = False
End If
Next
Else
msgbox objMSXML.parseError.reason
End If
请帮助我。提前谢谢你。
【问题讨论】:
-
“我们想要检测这样的nodeText没有提到任何评论是什么意思。” ?这很令人困惑。
标签: xml vbscript xml-parsing