3.4 DTD-Handling
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog SGML/XML parser
        • Predicate Reference
          • DTD-Handling
            • new_dtd/2
            • free_dtd/1
            • load_dtd/2
            • load_dtd/3
            • open_dtd/3
            • dtd/2
            • dtd_property/2
            • The DOCTYPE declaration
Availability::- use_module(library(sgml)).(can be autoloaded)
Sourcedtd(+DocType, -DTD)
Find the DTD representing the indicated doctype. This predicate uses a cache of DTD objects. If a doctype has no associated dtd, it searches for a file using the file search path dtd using the call:
...,
absolute_file_name(dtd(Type),
                   [ extensions([dtd]),
                     access(read)
                   ], DtdFile),
...

Note that DTD objects may be modified while processing errornous documents. For example, loading an SGML document starting with <?xml ...?> switches the DTD to XML mode and encountering unknown elements adds these elements to the DTD object. Re-using a DTD object to parse multiple documents should be restricted to situations where the documents processed are known to be error-free.

The DTD html is handled separately. The Prolog flag html_dialect specifies the default html dialect, which is either html4 or html5 (default).3Note that HTML5 has no DTD. The loaded DTD is an informal DTD that includes most of the HTML5 extensions (http://www.cs.tut.fi/~jkorpela/html5-dtd.html). In addition, the parser sets the dialect flag of the DTD object. This is used by the parser to accept HTML extensions. Next, the corresponding DTD is loaded.