1

When I seprate the "ATTRIBUTE" and "SCRIPT" xml node in diffrent xml file then I am able to read the file successfully. But when I combined these two node in single xml file then I am not able to read the xml file. So please help me for this. Thankk you very much in advance for your help.

This is my xml file

<ATTRIBUTES>
    <ETTOOLNAME>ECATT</ETTOOLNAME>
    <ETOBJ_GNDT>
        <VERSION>00000001</VERSION>
           <TWB_TITLE>TF_FI_FP_FI_0569_MS07_CO_Search_Help_Internal_Orders_vTD0_1_EN.x</TWB_TITLE>
        <TWB_STATUS>X</TWB_STATUS>
        <TWB_RELE>N</TWB_RELE>
        <FUSER>ECATT</FUSER>
        <FDATE>2014-05-22</FDATE>
        <LUSER>ECATT</LUSER>
        <LDATE>2014-05-22</LDATE>
        <LTIME>13:59:50</LTIME>
    </ETOBJ_GNDT>
    <ETOBJNOVER>
        <NAME>ZX_FI_FP_0569_MS07_COAS_FB01</NAME>
        <TYPE>ECSC</TYPE>
        <TWB_RESP>ECATT</TWB_RESP>
        <TWB_DISTL>B</TWB_DISTL>
        <DEVCLASS>Z_SOL_ONEERP</DEVCLASS>
        <MASTERLANG>E</MASTERLANG>
        <TADIR_RESP>ECATT</TADIR_RESP>
        <FRANGE>BC</FRANGE>
    </ETOBJNOVER>
    <ETOBJ_DOC>
        <SEARCH_1>FI_FP_FI_0569_MS07</SEARCH_1>
        <SEARCH_2>COAS</SEARCH_2>
        <SEARCH_3>KO03</SEARCH_3>
    </ETOBJ_DOC>
    <ETOBJ_CNST>
        <TWB_WKREQ>0.000</TWB_WKREQ>
        <TWB_PRIO>3</TWB_PRIO>
    </ETOBJ_CNST>
    <ETSC_TSYS>
        <SYSTEMDATA>Z_SD_1ERP_Z</SYSTEMDATA>
        <TESTSYSTEM>FI_TRUSTED_EN</TESTSYSTEM>
    </ETSC_TSYS>
    <ETSYS_COMP_TABTYPE/>
    <ETSYS_REL_TABTYPE/>
</ATTRIBUTES>


  <SCRIPT>
    <ETXML_LINE_TABTYPE>
        <item>*******************************************************************************.</item>
        <item>* Information.</item>
        <item>********************************************************************************.</item>
        <item>* Script for test case 'TF_FI_FP_FI_0569_MS07_CO_Search_Help_Internal_Orders_vTD0_1_EN.x'</item>
        <item>*</item>
        <item>* For Sub script:</item>
        <item>*  'Test case 3: Choose an Internal Order in One.Fi using external order number while transaction posting (positive case)'.</item>
        <item>*</item>
        <item>* Script is to Display Internal Order using external order number while Transaction Posting 'FB01'</item>
        <item>* GETTAB command is being used to fetch the data from 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>* To get the 'Table Entries' from table 'COAS'.</item>
        <item>  GETTAB ( COAS , COAS_1 ).</item>
        <item>* To display the value for the field 'External Order No'.</item>
        <item>  LOG ( V_EXTERNAL_ORDER_NO_FRM_TABL ).</item>
        <item/>
        <item>*----------------------Posting(FB01)-------------------------------------------*.</item>
        <item/>
        <item>* This part of Script is to Display Internal Order using external order number while Transaction Posting 'FB01'.</item>
        <item>MESSAGE ( MSG_1 ).</item>
        <item>* To get the name of the Title Screen.</item>
        <item>  GETGUI ( FB01_100_STEP_1 ).</item>
        <item>* Enter the Required details and Press Enter.</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>

And I have written vbscript as follows :

 Const XMLDataFile = "C:\temp\new\output.xml"

  Set xmlDoc = CreateObject("Microsoft.XMLDOM")
  xmlDoc.Async = False
  xmlDoc.Load(XMLDataFile)
  xmlDoc.validateOnParse=False

  strQuery1 = "/ATTRIBUTES/ETOBJ_GNDT/( VERSION | TWB_TITLE | TWB_STATUS | FUSER | FDATE | LUSER | LDATE )"

  Set colNodes = xmlDoc.selectNodes( strQuery1 )
  For Each objNode in colNodes
if(objNode.nodeName="VERSION") Then
Document.write("VERSION :  " & objNode.text & "<br><br>")
    'Document.write(objNode.nodeName & " :  " & objNode.text & "<br><br>")
End if

if(objNode.nodeName="TWB_TITLE") Then
    Document.write("SCRIPT TITLE :  " & objNode.text & "<br><br>")
End if

if(objNode.nodeName="TWB_STATUS") Then
    Document.write("SCRIPT STATUS :  " & objNode.text & "<br><br>")
End if

if(objNode.nodeName="FUSER") Then
    Document.write("CREATED BY :  " & objNode.text & "<br><br>")
End if

if(objNode.nodeName="FDATE") Then
    Document.write("CREATED ON :  " & objNode.text & "<br><br>")
End if

if(objNode.nodeName="LUSER") Then
    Document.write("CHANGED BY :  " & objNode.text & "<br><br>")
End if

if(objNode.nodeName="LDATE") Then
    Document.write("CHANGED ON :  " & objNode.text & "<br><br>")
End if

 Next

 strQuery2 = "/ATTRIBUTES/ETOBJNOVER/(NAME|TWB_RESP|DEVCLASS|FRANGE )"

 Set colNodes = xmlDoc.selectNodes( strQuery2 )

 For Each objNode in colNodes
 'Document.write(objNode.nodeName & " :  " & objNode.text & "<br><br>")

 if(objNode.nodeName="NAME") Then

   Document.write("SCRIPT NAME :  " & objNode.text & "<br><br>")

End if
if(objNode.nodeName="TWB_RESP") Then
    Document.write("PERSON RESPONSIBLE :  " & objNode.text & "<br><br>")
End if
if(objNode.nodeName="DEVCLASS") Then
    Document.write("PACAKGE :  " & objNode.text & "<br><br>")
End if
if(objNode.nodeName="FRANGE") Then
    Document.write("SOFTWARE COMPONENT :  " & objNode.text & "<br><br>")
End if

Next

strQuery3 = "/ATTRIBUTES/ETOBJ_DOC/(SEARCH_1|SEARCH_2 )"

Set colNodes = xmlDoc.selectNodes( strQuery3 )
For Each objNode in colNodes
'Document.write(objNode.nodeName & " :  " & objNode.text & "<br><br>")

if(objNode.nodeName="SEARCH_1") Then
    Document.write("SEARCH TERM 1 :  " & objNode.text & "<br><br>")
End if
if(objNode.nodeName="SEARCH_2") Then
    Document.write("SEARCH TERM 2 :  " & objNode.text & "<br><br>")
End if

 Next

strQuery4 = "/ATTRIBUTES/ETSC_TSYS/(SYSTEMDATA|TESTSYSTEM)"

Set colNodes = xmlDoc.selectNodes( strQuery4 )
For Each objNode in colNodes
'Document.write(objNode.nodeName & " :  " & objNode.text & "<br><br>")

if(objNode.nodeName="SYSTEMDATA") Then
    Document.write("SYSTEM DATA CONTAINER :  " & objNode.text & "<br><br>")
End if
if(objNode.nodeName="TESTSYSTEM") Then
    Document.write("TARGET SYSTEM :  " & objNode.text & "<br><br>")
End if


Next

Set objNodeList = xmlDoc.getElementsByTagName("SCRIPT") 

strValues = ""
If objNodeList.length > 0 then 
    For each x in objNodeList 
        If strValues = "" Then
            strValues = x.Text
        Else
            strValues = strValues & ";" & x.Text
        End If
    Next 
Else 
    strValues = ""
End If
If strValues = "" Then
    Document.write("No child elements found.")
Else
    arrValues = Split(strValues, ";")
    Document.write(Join(arrValues, VbCrLf))
End If

I want only those tag value whose tag name is <item>
How can i get it..?

1 Answer 1

2

You really should start all your XML work with a skeleton script like:

  Dim oFS      : Set oFS      = CreateObject("Scripting.FileSystemObject")
  Dim sFSpec   : sFSpec       = oFS.GetAbsolutePathName("..\testdata\xml\24078916-1.xml")
  Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument")
  objMSXML.setProperty "SelectionLanguage", "XPath"
  objMSXML.async = False
  objMSXML.load sFSpec

  If 0 = objMSXML.parseError Then
     ' do something sensible here
  Else
     WScript.Echo objMSXML.parseError.reason
  End If

that does minmimal error checking (and avoids atrocities like spurious ()). Applying this to your posted .XML:

Only one top level element is allowed in an XML document.

When I modify your .XML to

<root>
  ... your content ...
</root>

the skeleton script loads the .XML just fine.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi I have updated my code as per given your suggesion but it gives error like "Only one top level element is allowed in an XML document." what it means..? I can not disply/read more than two diffrent node..? please help me..
@Pravin - If you don't understand the error message, start your research here: w3.org/standards/xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.