WebXmlParseNodeAttribute Function

Action

Parses the response document with the defined content type (default: text/xml) and returns the XML attribute value of nodes attribute of the passed X-Path. 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. sBuffer will receive the parsed value.

Include file

WebAPI.bdh

Syntax

WebXmlParseNodeAttribute( out sBuffer      : string,
                          in  nBufferLen   : number,
                          in  sXPath       : string,
                          in  sAttribute   : string,
                          in  nOptions     : number optional,
                          in  sNamespaces  : string optional,
                          in  nOccurence   : number optional,
                          in  sContentType : string optional,
                          out nParsedBytes : number optional );
Parameter Description
sBuffer String variable that will receive the parsed XML attribute value
nBufferLen Maximum length of the string to return. If this parameter is omitted or set to STRING_COMPLETE all available data is stored in sResult.
sXPath X-Path query that specifies which XML node to parse
sAttribute Attribute of the resulting node of the X-Path query which value should be returned
nOptions (optional)

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.

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'

nOccurence

(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.

nParsedBytes (optional)

Number of bytes parsed into sBuffer

Example

dcltrans
  transaction TMain
  var
    hObject : number;
    sParsedValue1, sParsedValue2 : string;
  begin
    WebXmlParseNodeAttribute(sParsedValue1, STRING_COMPLETE, "/ProductsBooks/Products/Product[2]",,"name");
    WebXmlParseNodeAttribute(sParsedValue2, STRING_COMPLETE, "/ProductsBooks/Books/ns1:Book", "price", WEB_FLAG_DONT_FORCE_LOAD, "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>