#include "fivewin.ch"
#if ! defined( DEFAULT_MAX_RECORDS )
#define DEFAULT_MAX_RECORDS 20000
#endif
Static cDoc , cHttp
Function Main()
TRY
cDoc := CreateObject( "MSXML2.DOMDocument" )
CATCH
Alert("Error object MSXML2.DOMDocument : " + Ole2TxtError())
return NIL
END
TRY
cHttp := CreateObject( "MSXML2.XMLHTTP" )
CATCH
Alert("Error object MSXML2.XMLHTTP : " + Ole2TxtError())
END
checkVies( "BE", "0452109872" )
Return nil
//=========================================================================================
Function checkVies(cCountry, cVatNumber )
Local cResponse := " " ,hVar
Local cRequestXML := ""
local aData:={}
DEFAULT cCountry := "BE"
DEFAULT cVatNumber := "0452109872"
editvars cVatnumber
cRequestXML := [<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ] +;
[xmlns:tns1="urn:ec.europa.eu:types" ] +;
[xmlns:impl="urn:ec.europa.eu:checkVat"> ] +;
[<soap:Header> ]+;
[</soap:Header> ]+;
[<soap:Body> ]+;
[<tns1:checkVat xmlns:tns1="urn:ec.europa.eu:types" ]+;
[xmlns="urn:ec.europa.eu:types"> ]+;
[<tns1:countryCode>] + cCountry + [</tns1:countryCode> ] +;
[<tns1:vatNumber>] + cVatNumber + [</tns1:vatNumber> ] +;
[</tns1:checkVat> ]+;
[</soap:Body> ]+;
[</soap:Envelope> ]
//
//cHttp:Open( "POST","http://ec.europa.eu/taxation_customs/vies/services/checkVatService", .t.)
// Wait...
cHttp:Open( "POST","http://ec.europa.eu/taxation_customs/vies/services/checkVatService", .F.)
cHttp:SetRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" )
cHttp:setRequestHeader('User-Agent', 'node-soap')
cHttp:setRequestHeader('Accept' , 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8')
cHttp:setRequestHeader('Accept-Encoding', 'none')
cHttp:setRequestHeader('Accept-Charset', 'utf-8')
//cHttp:setRequestHeader('Connection', 'close')
//cHttp:setRequestHeader('Host', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService')
cHttp:setRequestHeader('SOAPAction', 'urn:ec.europa.eu:checkVat/checkVat')
//MsgGet( 'Wait',,@cRequestXML)
//cDoc:LoadXML( cRequestXML )
//lXmlHttp.send(lXmlDoc);
cHttp:send(cRequestXML)
//cHttp:send(cDOc:xml )
//If cHttp:status == 200
// ? cResponse
cResponse := cHttp:responseText
? cResponse
aadd(aData,BETWEENTAGSARRAY("name","/name",cResponse))
aadd(aData,BETWEENTAGSARRAY("address","/address",cResponse))
//xbrowser( BETWEENTAGSARRAY("faultstring","/faultstring",cResponse) )
xbrowser( aData )
//endif
RETURN NIL
FUNCTION BETWEENTAGSARRAY( cStartTag, cEndTag, cInputString, lIncludeTags )
LOCAL nStartPoint, nEndPoint
LOCAL nRecords := 00, nFetchLength := 00, aFoundText := Array( DEFAULT_MAX_RECORDS )
LOCAL cMDML
LOCAL cInputStringUpper := Upper( cInputString )
LOCAL cStartTagUpper := Upper( cStartTag )
LOCAL cEndTagUpper := Upper( cEndTag )
hb_Default( @lIncludeTags, .F. )
DO WHILE .T.
// Find the starting point of the starting tag.
nStartPoint := At( cStartTagUpper, SubStr( cInputStringUpper, 01 ) )
IF nStartPoint > 00
// Adjust starting point to end of starting tag
nStartPoint += Len( cStartTagUpper )
// If the first tag is found strip off string up to and including the starting tag itself
cInputStringUpper := SubStr( cInputStringUpper, nStartPoint )
cInputString := SubStr( cInputString, nStartPoint )
// Find the starting point of the second tag, beginning from end of first tag.
nEndPoint := At( cEndTagUpper, cInputStringUpper )
IF nEndPoint > 00
// If the second tag is found calculate its position from start of string.
nFetchLength := nEndPoint - 1
IF lIncludeTags
cMDML := cStartTag + LTrim( SubStr( cInputString, 01, nFetchLength ) ) + cEndTag
ELSE
cMDML := LTrim( SubStr( cInputString, 01, nFetchLength ) )
ENDIF
IF ++nRecords <= DEFAULT_MAX_RECORDS
aFoundText[ nRecords ] := cMDML
ELSE
// IF we get here it is gonna be oh so slow.
AAdd( aFoundText, cMDML )
ENDIF
// clip off the front of the string then loop to find the next
cInputStringUpper := SubStr( cInputStringUpper, nFetchLength + 01 )
cInputString := SubStr( cInputString, nFetchLength + 01 )
ELSE
EXIT
ENDIF
ELSE
EXIT
ENDIF
ENDDO
IF nRecords < DEFAULT_MAX_RECORDS
aFoundText := ASize( aFoundText, nRecords )
ENDIF
RETURN ( aFoundText )