WebXmlVerifyNodeValue Function

Action

Verifies a node's value in the nOccurrence'd document that matches the sContentType. Default sContentType is text/xml.

The value of the resulting X-Path query node will be verified against the sValue parameter value.

The response document has to be a valid XML document for the function to work properly. If the X-Path query string contains any elements with namespace prefixes, the namespaces have to be passed in sNamespaces.

Include file

WebAPI.bdh

Syntax

WebXmlVerifyNodeValue( in  sXPath       : string,
                       in  sValue       : string,
                       in  nAppearance  : number optional,
                       in  nOptions     : number optional,
                       in  sNamespaces  : string optional,
                       in  nOccurrence  : number optional,
                       in  sContentType : string optional,
                       in  nSeverity    : number optional := SEVERITY_ERROR,
                       out nResult      : number optional );
Parameter Description
sXPath X-Path query that specifies which XML node to verify
sValue String to compare with the parsed node value
nAppearance (optional)

Value to which the actual appearance of the specified content string is compared (see nOptions). If this parameter is omitted, the specified string must appear at least once to meet the verification rules.

nOptions

(optional)

WEB_FLAG_EQUAL
The verification succeeds if the actual appearance is equal to nAppearance.
WEB_FLAG_GREATER (default)
The verification succeeds if the actual appearance is greater than nAppearance.
WEB_FLAG_SMALLER
The verification succeeds if the actual appearance is smaller than nAppearance.
WEB_FLAG_CASE_SENSITIVE
If this flag is set the string compare operation is case sensitive.
WEB_FLAG_IGNORE_WHITE_SPACE
If this flag is set all whites paces are ignored.
WEB_FLAG_DONT_FORCE_LOAD
Specify this option to enable caching for subsequent requests. Note that this may lead to unpredictable behaviour, because the verification may only cover certain parts (which are loaded) of a page.
WEB_FLAG_ALL_RESPONSES
If this flag is specified all server responses are scanned (even redirection responses, which are normally not displayed by a browser).
WEB_FLAG_INCLUDE_EMBEDDED
If this flag is specified, even embedded documents can be specified by the nDocNum parameter. Normally the number of a document is defined by the occurrence of the source definition in an HTML document (src=...). If this flag is specified every embedded object increases this counter, which assigns higher numbers to subsequent frames.
WEB_FLAG_INCLUDE_HEADER
If this flag is specified the response header can also be verified.
WEB_FLAG_HEADER_ONLY
If this flag is specified only the response header is verified.
WEB_FLAG_RULE
Specify this flag to perform the verification on every subsequent web function. Verification functions with this flag are usually located in the TInit transaction. Call WebCancelAllRules() to disable all verification rules.
注: The option WEB_FLAG_RULE should only be used in the INIT transaction or in combination with the WebCancelAllRules function!
sNamespaces (optional)

Namespaces that should be recognized by the XML parser. If the x-path query contains any namespace prefixes, these prefixes have to be defined in this namespace string in the way xmlns:prefix=namespace. Multiple namespaces can be defined by separating them with a blank: xmlns:ns1= 'http://www.MyCompany.com/ns1' xmlns:ns2= 'http://www.MyCompany.com/ns2'

nOccurrence (optional)

If defined, the nOccurrence'd document that matches the content type will be parsed. Default value is 1.

sContentType (optional)

Default: text/xml

Only documents of the passed content type will be parsed. If you pass a blank, all content types will be accepted.

nSeverity Optional: Severity of the error that is raised if the verification fails. Can be one of the following values:
  • SEVERITY_SUCCESS: Success; no error (numerical value: 0)
  • SEVERITY_INFORMATIONAL: Informational; no error (numerical value: 1)
  • SEVERITY_WARNING: Warning; no error (numerical value: 2)
  • SEVERITY_ERROR: (Default) Error; simulation continues (numerical value: 3)
  • SEVERITY_TRANS_EXIT: Error; the active transaction is aborted (numerical value: 4)
  • SEVERITY_PROCESS_EXIT: Error; the simulation is aborted (numerical value: 5)
nResult (optional)

If a variable is provided, it will receive the number of appearances of the specified content string.

Example

dcltrans
  transaction TMain
  var
    hObject       : number;
    sParsedValue1 : string;
    sParsedValue2 : string;
    sParsedValue3 : string;
  begin
    WebXmlVerifyNodeValue("/ProductsBooks/Products/Product[2]", "This is product2");
    WebXmlVerifyNodeValue("/ProductsBooks/Products/Product[@name='Product1']","This is product1");
    WebXmlVerifyNodeValue("/ProductsBooks/Books/ns1:Book", "Lord of the Rings", 1, 0, "xmlns:ns1='http://book'");
    WebPageUrl("http://localhost/productsandbooks.xml");
  end TMain;

XML Document for the sample above

<?xml version="1.0" ?>
<ProductsBooks>
<Products>
<Product name='Product1'>This is product1</Product>
<Product name='Product2'>This is product2</Product>
</Products>
<Books xmlns:bookns='http://book'>
<bookns:Book price='20.95'>Lord of the Rings</bookns:Book>
<bookns:Book price='18.70'>Star Wars - Episode I</bookns:Book>
</Books>
</ProductsBooks>