find text in XML node using vbscript -


i have xml :

<ecsc>   <script>  <etxml_line_tabtype>                 <item>*******************************************************************************.</item>         <item>* information.</item>         <item>********************************************************************************.</item>         <item>* script test case 'tf_fi_fp_fi_0569_ms07_co_search_help_internal_orders_vtd0_1_en.x'</item>         <item>*</item>         <item>* sub script:</item>         <item>*  'test case 3: choose internal order in one.fi using external order number while transaction posting (positive case)'.</item>         <item>*</item>         <item>* script display internal order using external order number while transaction posting 'fb01'</item>         <item>* gettab command being used fetch data table 'coas'.</item>         <item>*</item>         <item>*</item>         <item>*     test data related information</item>         <item>*     -----------------------------</item>         <item>* default test data present in parameter list has been used while scripting ( script recording &amp; performing checks ).</item>         <item>*</item>         <item>* final execution of result log: 0000037077.</item>         <item>*</item>         <item>********************************************************************************.</item>         <item>* preparation.</item>         <item>********************************************************************************.</item>         <item/>         <item/>         <item>********************************************************************************.</item>         <item>* end preparation.</item>         <item>********************************************************************************.</item>         <item/>         <item/>         <item>********************************************************************************.</item>         <item>* execution.</item>         <item>********************************************************************************.</item>         <item>* 'table entries' table 'coas'.</item>         <item>  gettab ( coas , coas_1 ).</item>         <item>* display value field 'external order no'.</item>         <item>  log ( v_external_order_no_frm_tabl ).</item>         <item/>         <item>*----------------------posting(fb01)-------------------------------------------*.</item>         <item/>         <item>* part of script display internal order using external order number while transaction posting 'fb01'.</item>         <item>message ( msg_1 ).</item>          <item>  getgui ( fb01_100_step_1 ).</item>          <item>  sapgui ( fb01_100_step_2 ).</item>         <item>* enter amount , tax code.</item>         <item>* and, press f4 in order field.</item>         <item>  sapgui ( fb01_300_step_1 ).</item>         <item>* in f4 screen, enter 'external order number'</item>         <item>* pop-up screen displayed entries order, description , external order number , select 1st order row, press enter.</item>         <item>  sapgui ( fb01_200_step_1 ).</item>         <item>* values field 'order, description , external order no' f4 help.</item>         <item>  getgui ( fb01_120_step_1 ).</item>         <item>* press 'enter' button.</item>         <item>  sapgui ( fb01_120_step_3 ).</item>         <item>* value field 'order' main screen.</item>         <item>  getgui ( fb01_300_step_2 ).</item>         <item>* click on 'f3' button.</item>         <item>  sapgui ( fb01_300_step_3 ).</item>         <item>* click on 'f3' 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' button.</item>         <item>  sapgui ( fb01_100_step_3 ).</item>         <item>endmessage ( e_msg_1 ).</item>         <item/>         <item>* display title screen.</item>         <item>  log ( v_title_screen ).</item>         <item>* display 'order' number f4 help.</item>         <item>  log ( v_order_no_from_f4 ).</item>         <item>* display 'description' f4 help.</item>         <item>  log ( v_description_from_f4).</item>         <item>* display 'external order no' value f4 help.</item>         <item>  log ( v_external_order_no_from_f4 ).</item>         <item>* display 'order' number 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>* check name of title screen transaction fb01.</item>         <item>  chevar ( v_title_screen = i_title_screen ).</item>         <item>* check value field 'external order no' f4 help, should equal 'external order no' table.</item>         <item>  chevar ( v_external_order_no_frm_tabl = v_external_order_no_from_f4 ).</item>         <item>* check values field 'order' number table, should equal 'order' no f4 screen , main screen.</item>         <item>  chevar ( ( i_order_number_from_table = v_order_no_from_f4 ) , ( i_order_number_from_table = v_order_no_frm_main_screen )).</item>         <item>********************************************************************************.</item>         <item>* end check.</item>         <item>********************************************************************************.</item> </etxml_line_tabtype>   </script>        </ecsc> 

from above xml file want check "message" block "endmessage" block whether block contain statement "sapgui" exist or not. if word "sapgui" not exist in above xml message block vbscript should display error. tried vb script code :

 dim ofs      : set ofs  = createobject("scripting.filesystemobject")  dim sfspec   : sfspec   = ofs.getabsolutepathname("d:\new\link\xmlsample.xml")  dim objmsxml : set objmsxml = createobject("msxml2.domdocument")  objmsxml.setproperty "selectionlanguage", "xpath"  objmsxml.async = false  objmsxml.load sfspec  sapgui=0  set onodelist2 = objmsxml.documentelement.selectnodes("/ecsc/script/etxml_line_tabtype/item")  each nditem in onodelist2        dim sitem : sitem = nditem.text        if (left(sitem, 7)="message")       if (left(sitem, 8)="  sapgui")         sapgui=sapgui+1         msgbox("sapgui present")       else             if(sapgui = 0)                 msgbox("sapgui code not present")         end if       end if   end if  next 

please me this. thank in advance.

you can make better use of xpath matching want. used exact same sample xml gave , came this:

option explicit  dim xml : set xml = createobject("msxml2.domdocument.6.0") call xml.setproperty("selectionlanguage", "xpath") xml.async = false call xml.load("test.xml")  dim nl : set nl = xml.documentelement.selectnodes("//etxml_line_tabtype/item[text()='message.']/../item[contains(.,'sapgui')]")  if nl nothing or nl.length < 1   call msgbox("error", vbcritical, "error") end if  wscript.quit 

it give error if 'item' node containing text 'message.' not have sibling 'item' node containing text 'sapgui'


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -