xml ppt (1)

Embed Size (px)

Citation preview

  • 8/8/2019 xml ppt (1)

    1/18

    PREPARED BY:

    SAGAR CHAITANYAVENKATESH HEMANTHMAHESH SUJAN

  • 8/8/2019 xml ppt (1)

    2/18

  • 8/8/2019 xml ppt (1)

    3/18

    ROOT ELEMENT

    (PARENT ELEMENT)CHILDPARENT

    ELEMENT

    (CHILD ELEMENT)

    TITLE AUTHOR

    ATTRIBUTE:PUBLISHED

  • 8/8/2019 xml ppt (1)

    4/18

    SAMPLE XML FILE.

    Romeo and Juliet

    William Shakespeare

  • 8/8/2019 xml ppt (1)

    5/18

    OBJECTIVE:

    y Usage ofMicrosoft.XMLDOM to read andparse XML file from QuickTest Professional(QTP)

    y Usage ofXPath for performing differentqueries to extract required data

  • 8/8/2019 xml ppt (1)

    6/18

    MicrosoftsXML Parser also known as Microsoft.XMLDOM. ThisXML parser allows running XPATH queries.

    DOM -> Document Object Model

    The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects inHTML, XHTML and XML documents.

    Uses a scripting languageand valid markup (HTML/XHTML/XML/etc.)

    Can be used with any programming/scripting language

  • 8/8/2019 xml ppt (1)

    7/18

    Async is a property ofMicrosoft.XMLDOM.The property specifies whether asynchronous download ofthe document is permitted.(xmlDoc.Async = False).

    The Async property specifies whether downloading ofan XML file should be handled asynchronously or not.

    True means that the load() method returns the control

    to the caller before the download is complete.False means that the download must be completed

    before the caller gets the control back.

  • 8/8/2019 xml ppt (1)

    8/18

    Load method loads an XML document from thespecified file.

  • 8/8/2019 xml ppt (1)

    9/18

    Loading of XML file in QTP:

    ConstXMLDataFile = "C:\TestData.xml

    SetxmlDoc = CreateObject("Microsoft.XMLDOM")

    xmlDoc.Async =FalsexmlDoc.Load(XMLDataFile)

  • 8/8/2019 xml ppt (1)

    10/18

    Expression Description

    nodename Selects all child nodes of the named node

    / Selects from the root node

    // Selects nodes in the document from the current node that match theselection no matter where they are

    . Selects the current node

    .. Selects the parent of the current node

    @ Selects attributes

    The XML Path Language, is a query language for selecting nodes from an XML document.

  • 8/8/2019 xml ppt (1)

    11/18

    y SelectNodes:

    Selects a list of nodes matching the XPATH expression.

    Syntax:Xmldoc .SelectNodes (XPATH)

    y SelectSingleNode:

    Selects the XMLNode that matches the XPATH expression

    Syntax:

    Xmldoc .SelectSingleNode (XPATH)

  • 8/8/2019 xml ppt (1)

    12/18

    1.How to get number of books in a bookstore?

    The QTP script is:

    Set nodes = xmlDoc. SelectNodes("/bookstore/book")MsgBox "Total books: " & nodes. Length

  • 8/8/2019 xml ppt (1)

    13/18

    2.Howto gettitleofthefirst book?

    QTP script is:

    Set node=xmlDoc. SelectSingleNode("/bookstore/book[0]/title/text()")MsgBox"Titleof1st book: " &node.NodeValue

    Set node=xmlDoc. SelectSingleNode("/bookstore/book[1]/title/text()")

    Note: Pay attention that nodes are zero-indexed, i.e. first book isbook[0], second book is book[1], and so on.

  • 8/8/2019 xml ppt (1)

    14/18

    3.Howto gettitlesofall booksina bookstore?QTP script gets list of books from XML file and iterates them through:

    ' getalltitlesSet nodes=xmlDoc.SelectNodes("/bookstore/book/title/text()")

    ' gettheir valuesFori=0To(nodes.Length - 1)

    Title=nodes(i).NodeValue

    MsgBoxTitleNextThe result is:

  • 8/8/2019 xml ppt (1)

    15/18

    4.Howto gettitlesofall John Smith's books?

    QTP script is:' getlistofJohn Smith's booksSet nodes=xmlDoc.SelectNodes("/bookstore/book/title[../author='JohnSmith']/text()")

    ' gettheirtitlesFori=0To(nodes.Length - 1)

    Title=nodes(i).NodeValueMsgBoxTitle

    Next

  • 8/8/2019 xml ppt (1)

    16/18

    5.Howto gettitlesofall books publishedafter2003?

    QTP script is:' getlistofbooks publishedafter2003Set nodes=xmlDoc.SelectNodes("/bookstore/book/title[@published >2003]/text()")

    ' gettheirtitlesFori=0To(nodes.Length - 1)

    Title=nodes(i).NodeValueMsgBoxTitle

    Next

  • 8/8/2019 xml ppt (1)

    17/18

    y http://www.w3schools.com/XPath/xpath_syntax.asp

    y http://motevich.blogspot.com/2008/09/how-to-read-xml-file-

    from-qtp_08.html

  • 8/8/2019 xml ppt (1)

    18/18