XML Backend Architecture#
Docling ships four specialized XML backends under docling/backend/xml/, each targeting a distinct domain-specific XML schema. All four implement DeclarativeDocumentBackend, use SimplePipeline, and do not support pagination. They are registered as separate InputFormat enum values rather than sharing a single generic XML backend .
| Backend | Class | InputFormat | File Extensions | Optional Extra |
|---|---|---|---|---|
| JATS | JatsDocumentBackend | XML_JATS | .xml, .nxml | format-xml-jats |
| XBRL | XBRLDocumentBackend | XML_XBRL | .xml, .xbrl | format-xml-xbrl |
| USPTO | PatentUsptoDocumentBackend | XML_USPTO | .xml, .txt | format-xml-uspto |
| DocLang | DocLangDocumentBackend | XML_DOCLANG | .dclg, .dclg.xml | (none, base dep) |
JATS — Journal Article Tag Suite#
jats_backend.py parses scientific articles from PubMed Central, bioRxiv, medRxiv, and Springer Nature . It uses lxml + BeautifulSoup4 and identifies valid JATS documents by checking the DTD system URL for JATS-journalpublishing or JATS-archive keywords .
Parsing flow: metadata (title, authors, affiliations, abstract) is extracted first via XPath, then the <body> and <back> subtrees are walked linearly by _walk_linear(). Element handlers cover sections (<sec>), lists, figures with captions, tables (delegated to HTMLDocumentBackend cell-span logic), footnote groups, reference lists, and inline/block equations via <tex-math> .
Security: The lxml.etree.XMLParser is constructed with resolve_entities=False, load_dtd=False, no_network=True, and dtd_validation=False to block XXE and XML bomb attacks .
Install: pip install 'docling-slim[format-xml-jats]' (requires lxml and beautifulsoup4).
XBRL — eXtensible Business Reporting Language#
xbrl_backend.py handles financial/regulatory XML (SEC filings, etc.) via the Arelle library . It is the only XML backend with typed BackendOptions: XBRLBackendOptions exposes enable_local_fetch, enable_remote_fetch, and taxonomy (path to a local taxonomy directory).
The convert() method :
- Extracts document metadata (type, organization, period) from XBRL facts.
- Converts
textBlockItemTypefacts toDoclingDocumentfragments viaHTMLDocumentBackendand concatenates them. - Encodes numeric facts as
GraphCell/GraphLinkstructures capturing value, period, unit, decimals, and dimensional context. - Builds a presentation linkbase hierarchy (parent-child concept tree) and a calculation linkbase (summation relationships with weights).
Remote access is disabled by default (cntlr.webCache.workOffline = True) unless enable_remote_fetch=True is set explicitly .
Install: pip install 'docling-slim[format-xml-xbrl]' (requires arelle-release).
USPTO — US Patent Office#
uspto_backend.py covers patent grants since 1976 and applications since 2001 across four distinct sub-formats, dispatched by the <!DOCTYPE> declaration or PATN sentinel :
| Sub-parser class | Coverage |
|---|---|
PatentUsptoGrantAps | APS text format, grants 1976–2001 |
PatentUsptoGrantV2 | XML v2.5, grants 2002–2004 |
PatentUsptoIce | XML v4.x ICE, grants/apps 2005+ |
PatentUsptoAppV1 | XML v1.x, applications 2001–2004 |
All XML sub-parsers use SAX streaming via defusedxml.sax.make_parser() with a PatentHandler (ContentHandler) that accumulates title, abstract, claims, headings, paragraphs, and table placeholders into a DoclingDocument . Tables are extracted separately by regex then re-parsed by XmlTable using the OASIS Open XML Exchange Table Model.
Security: USPTO files require DTD declarations, so a custom defusedxml.sax configuration is used: external entity resolution is blocked via feature_external_ges=False / feature_external_pes=False, while DTD declarations themselves are permitted (forbid_dtd=False). The detailed security rationale is documented in the module header.
Install: pip install 'docling-slim[format-xml-uspto]' (requires defusedxml and beautifulsoup4).
DocLang — Docling Semantic XML#
doclang_backend.py is the input side of Docling's own XML format. The backend reads the file as UTF-8 text and delegates entirely to DocLangDocDeserializer.deserialize_str() from docling-core . No extra install is needed; docling-core is a base dependency.
DocLang supports bidirectional conversion: DoclingDocument can be exported to DocLang via export_to_doclang() / save_as_doclang() / save_as_doclang_archive(), and re-imported here. For more detail on the format itself, see the DocLang Format knowledge base article .
Placement in the Backend Hierarchy#
All four live in the backend/xml/ subdirectory and appear alongside all other format backends in the Document Backends reference . Format options are registered in DocumentConverter and default options are returned by _get_default_option() .
Example usage:
from docling.document_converter import DocumentConverter
from docling.datamodel.base_models import InputFormat
# JATS
DocumentConverter(allowed_formats=[InputFormat.XML_JATS]).convert("article.nxml")
# XBRL (offline)
from docling.datamodel.backend_options import XBRLBackendOptions
from docling.document_converter import XBRLFormatOption
converter = DocumentConverter(
allowed_formats=[InputFormat.XML_XBRL],
format_options={InputFormat.XML_XBRL: XBRLFormatOption(
backend_options=XBRLBackendOptions(enable_local_fetch=True, enable_remote_fetch=False)
)}
)