libxml2
 
De-facto standard library for accessing xml files.

Website: http://xmlsoft.org/
Platforms supported: Windows (32-bit and 64-bit), Linux, FreeBSD, Haiku
Headers to include: libxml/*.bi
Header version: 2.9.2
Examples: in examples/xml/

Haiku R1 beta 6 amd64: `examples/xml/libxml.bas` compiled and ran with
FreeBASIC 1.20.4-3 against HaikuPorts libxml2 2.15.3, reading a controlled XML
fixture with the text-reader API.

The reader example checks nullable xmlTextReaderConstName and xmlTextReaderConstValue results before using the borrowed strings. It prints node information until xmlTextReaderRead reports end of input or an error, frees the reader, and returns a failing process status for malformed, empty, missing or unfinished XML. Process-wide cleanup runs after the last reader. It does not substitute entities and requests XML_PARSE_NONET.

Windows qualification uses the installed libxml2 2.15.3 SDK with both compiler backends and both architectures. Older declarations remain in the binding; these checks exercise the reader API used by the examples, not every historical public structure.

Example

'' FreeBASIC XML examples
'' File: libxml.bas
'' Purpose: Display XML reader nodes and report parse failure.
'' Responsibilities: Check nullable borrowed strings and release the reader.
'' This file contains no DOM ownership, entity substitution or concurrent readers.

#include Once "libxml/xmlreader.bi"

Function main() As Integer
    Dim filename As String = Command(1)
    If Len(filename) = 0 Then
        Print "Usage: libxml filename"
        Return 1
    End If
    Dim reader As xmlTextReaderPtr = xmlReaderForFile(filename, NULL, XML_PARSE_NONET)
    If reader = NULL Then
        xmlCleanupParser()
        Print "Unable to open "; filename
        Return 1
    End If
    Dim result As Long = xmlTextReaderRead(reader)
    Do While result = 1
        '' ConstName and ConstValue borrow reader storage. Some nodes have no
        '' value or name, so do not dereference a missing pointer.
        Dim constname As Const ZString Ptr = xmlTextReaderConstName(reader)
        Dim value As Const ZString Ptr = xmlTextReaderConstValue(reader)
        Dim name_text As String, value_text As String
        If constname <> NULL Then name_text = *constname
        If value <> NULL Then value_text = *value
        Print xmlTextReaderDepth(reader); xmlTextReaderNodeType(reader); " "; name_text; _
              xmlTextReaderIsEmptyElement(reader); xmlTextReaderHasValue(reader); value_text
        result = xmlTextReaderRead(reader)
    Loop
    xmlFreeTextReader(reader)
    '' Process-wide cleanup belongs after the last reader, not in a callback.
    xmlCleanupParser()
    If result <> 0 Then
        Print "failed to parse: "; filename
        Return 1
    End If
    Return 0
End Function

End main()

'' end of libxml.bas