Forum Discussion

rajesh_makiredd's avatar
rajesh_makiredd
Occasional Contributor
11 years ago

XML object initialization

 Hi,



I have written the script to initialize the xml object. Please look into the code once.




Function webservice(tag)


 


    set xmlDoc = CreateObject("Microsoft.XMLDOM")


    xmlDoc.async="false"


    xmlDoc.load("D:\webservice\test.xml")


    Application = xmlDoc.GetElementsByTagName(tag).item(0).text()


    


'    Set Application = xmlDoc.DocumentElement


'    set a= Application.SelectNodes(tag) 


'    Log.message a


    TagValue=  application


    Log.Message("tag value is" &tagvalue)


    


end function



But while executing the above script getting VB script error.

Error is:- 


Object required: 'xmlDoc.GetElementsByTagName(...).item(...)'


Unit: "Unit1" Line: 12 Column: 5.




Please suggest me..

Thanks in advance..

5 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi rajesh, you shouldn't need any configuration to get this to work.

     


    Have you also changed the first method call to use a lower case g?


     


    I.e, your sample has xmlDoc.GetElementsByTagName where it should be xmlDoc.getElementsByTagName


     


    If it still does not work, I suggest you use the debugger to evaluate the objects in the xmlDoc.GetElementsByTagName(tag).item(0).text object chain to determine at which point it is failing.


     


    Regards,


    Phil Baird

  • Hi Rajesh,

     


    Also, I would suggest that you check whether the getElementsByTagName method returns some objects before starting accessing them. For example:


    Set elemets = xmlDoc.getElementsByTagName(tag)


    If elements.length > 1 then


    ....


     

  • Also, check for XML parsing errors:



    xmlDoc.load("D:\webservice\test.xml")

    If xmlDoc.parseError = 0 Then

      ' Continue

    Else

      Call Log.Error(xmlDoc.parseError.reason)

    End If

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi rajesh, remove the () after text(), i.e.

     


    Application = xmlDoc.GetElementsByTagName(tag).item(0).text()


     


    should be


     


    Application = xmlDoc.getElementsByTagName(tag).item(0).text


     


    As per the debugger, text is a Property, not a Method.


     


    Regards,


    Phil Baird

  • rajesh_makiredd's avatar
    rajesh_makiredd
    Occasional Contributor
    Hi phil,





    After removing the () after text property also same problem.

    It is saying object  required. I think XMLDOM object is not initialized properly. Is there any configuration ?.