Posted by Albert Gareev on Dec 30, 2009
Parent page: Service Functions – XML (QTP, VBScript)
Answers
Description
Open XML file - load into memory - locate target nodes - update (replace) values - save XML file (either under a new name or overwrite the original file).
Search is performed by tag name (“target_node”).
If you pass in a non-string parameter for .SetValue function, convert it first by using CStr().
Set [...] ...
Posted by Albert Gareev on Dec 29, 2009
Parent page: Service Functions – XML (QTP, VBScript)
Answers
1. How to count all direct children?
Set objColl = objParent.ChildElements()
intCount = objColl.Count
2. How to count all direct children, specific name tag?
Set objColl = objParent.ChildElementsByPath("./wanted")
intCount = objColl.Count
3. How to count all descendants?
Set objColl = ...
Posted by Albert Gareev on Dec 09, 2009
Parent page: Service Functions – System (QTP, VBScript)
Description
If you need to generate text file with values you don’t know ahead you may do it dynamically, by utilizing the function below. Make sure you designed template first.
The current logic is oriented to executable text files generation, like Dexterity Macro or OS Shell batch files. Code lines are data-driven, if data not [...] ...
Posted by Albert Gareev on Dec 03, 2009
Root page: Service Functions – XML (QTP, VBScript)
Parent page: XSL introduction and references
Related post: Text File compare in “WDIFF” style (QTP, VBScript, XML, XSL) – Instructions and XSL script
Sample task
After line by line (and word by word) text file comparison has been performed, XML log was produced.
Review the log, identify and report found issues.
Sample ...
Posted by Albert Gareev on Dec 02, 2009
Root page: Service Functions – XML (QTP, VBScript)
Parent page: XSL introduction and references
Sample task
Verify “transactions” xml file consisting of 10-1000 records.
Only “debit” or “credit” record names are valid. Any other entries must be located and reported.
Additionally, identify and report all debit records with debit amount greater than 50.00
Sample XML
<?xml version="1.0" ...
Posted by Albert Gareev on Nov 30, 2009
Parent page: Service Functions – XML (QTP, VBScript)
What is XSL?
The Extensible Stylesheet Language.
An XSL script is a set of transformation instructions used by an engine (often, web browser, but could be any other processing program as well) to produce a new document based on XML input document. The original document remains unchanged.
The output document format can be another [...] ...
Posted by Albert Gareev on Nov 23, 2009
Parent page: Service Functions – XML (QTP, VBScript)
Note. Although there could be no “reusable function” that would construct XPath for you, I store current post under “XML Service Functions” category, as it’s closely related to it. XPath is fairly simple to learn and very powerful in use.
You can use free XPath Designer Tool to validate queries you [...] ...
Posted by Albert Gareev on Nov 15, 2009
Parent page: Service Functions – XML (QTP, VBScript)
Description
This particular example demonstrates adding XSL call that contains instructions transforming XML tree to a web-page (HTML).
Built-in QTP support for XML does not provide mapping for XML methods that operate special nodes, like Processing Instructions. It can be done through Microsoft XML DOM object.
Dim objXMLDoc
Dim objNode
Set objXMLDoc = ...
Posted by Albert Gareev on Nov 14, 2009
Parent page: Service Functions – XML (QTP, VBScript)
Description
Uses .AddChildElementByName method to create a child XML node, then returns reference to the newly created object. If Parent XML node is not defined returns “Nothing”.
Public Function CreateChildElementByName(ByRef objXMLParent, ByVal sTagName, ByVal sInnerText)
Dim objColl
If objXMLParent is Nothing Then
Set CreateChildElementByName = ...
Posted by Albert Gareev on Oct 02, 2009
In the code examples I present I often refer to routine functions. In my framework I have specialized libraries to call from.
In my blog I maintain the similar structure.
Using built-in QTP-XML Objects and Functions
Returns reference of XML Element
Returns text value of XML Element
Returns reference of XML Attribute
Returns text value of XML Attribute
Returns text value of a [...] ...