WebXmlGetDocument Function

Action

If the next web request returns an XML document, the document will be parsed by the XML dom parser and the handle to the document will be stored in hDocument. If there is no document that can be parsed, the handle will be 0.

nOccurrence specifies that the nOccurrence'd document of the next request that matches the content type should be parsed. Default value is 1.

If sContentType is defined only documents of that content type will be parsed. Default value is "text/xml".

Note: Use the XmlFreeHandle function in your script to free any open handles and to avoid increasing memory usage.

Include file

WebAPI.bdh

Syntax

WebXmlGetDocument( out hDocument    : number,
                   in  nOccurrence  : number optional,
                   in  sContentType : string optional ): boolean;

Return value

  • true if successful

  • false otherwise

Parameter Description
hDocument Will hold the handle to the parsed document after the next web request.
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.

Example

dcltrans
  transaction TMain
  var 
    hObject, hDoc : number;
    sXML          : string;
  begin
    WebXmlGetDocument(hDoc);
    WebPageUrl("http://localhost/productsandbooks.xml");
    if(hDoc <> 0) then
      XmlGetXml(hDoc, sXML);
      writeln(sXML);
    end;
  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>