Sample code for 30+ languages & platforms
PureBasic

Load XML from a Remote URL

Demonstrates how to load XML from a remote URL, such as https://www.chilkatsoft.com/hamlet.xml

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkXml.pb"

Procedure ChilkatExample()

    success.i = 0

    ; This example assumes the Chilkat HTTP API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    sbXml.i = CkStringBuilder::ckCreate()
    If sbXml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Download the XML from the URL into sbXml
    success = CkHttp::ckQuickGetSb(http,"https://www.chilkatsoft.com/hamlet.xml",sbXml)
    If success = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbXml)
        ProcedureReturn
    EndIf

    xml.i = CkXml::ckCreate()
    If xml.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ; Load the XML contained in sbXml
    success = CkXml::ckLoadSb(xml,sbXml,1)
    If success = 0
        Debug CkXml::ckLastErrorText(xml)
        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbXml)
        CkXml::ckDispose(xml)
        ProcedureReturn
    EndIf

    Debug "Success."


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbXml)
    CkXml::ckDispose(xml)


    ProcedureReturn
EndProcedure