Forum Discussion

DevaV's avatar
DevaV
Contributor
14 years ago

X-Query in Test complete

Hi,



I would like to use XQuery to fetch datas  from XML. Is there any possiblity to use x-query in test-complete using java scripts.



Looking forward for your suggestions on this.

2 Replies

  • Deva,


    I don't think it's possible to use XQuery syntax and  FLWOR expressions directly in TestComplete scripts.


    You can try working with XML documents using the Microsoft DOM objects.

    Below, is a code snippet that demonstrates this:




    function test()

    {

      var xmlDoc, s;

     

      // Specify your file name

      var FileName = "C:\\My Folder\\My Project\\My_File.xml";

     

      // Load xml file

      xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");

      xmlDoc.load(FileName);


      // Check errors

      if (xmlDoc.parseError.errorCode != 0)

      {

        s = "Reason: " + xmlDoc.parseError.reason + "\n" +

            "Line: " + xmlDoc.parseError.line + "\n" +

            "Text: " + xmlDoc.parseError.srcText;

        Log.Error("Failed to open file " + FileName, s);

        return;

      }


      // Specify your XPath expression

      var xmlNode = xmlDoc.selectSingleNode("//rootElement/headerElement/@textAttr");

       

      if (xmlNode != null)

        Log.Message(xmlNode.text);

      else

        Log.Message("Not found");

    }

  • Hi Alex ,



    Thansk for your information. We have tried with DOM objects already but was little curious to know whether XQuery could be implemented.



    Thanks.