<detect> Content: and|dtdPublicId|dtdSystemId|fileNameExtension|mimeType| not|or|rootElementLocalName|rootElementNamespace|schemaType </detect> <and> Content: [ and|dtdPublicId|dtdSystemId|fileNameExtension|mimeType| not|or|rootElementLocalName|rootElementNamespace|schemaType ]+ </and> <dtdPublicId substring = boolean : false > Content: non empty token </dtdPublicId> <dtdSystemId> Content: anyURI </dtdSystemId> <fileNameExtension> Content: file name extension </fileNameExtension> <mimeType> Content: non empty token </mimeType> <not> Content: and|dtdPublicId|dtdSystemId|fileNameExtension|mimeType| not|or|rootElementLocalName|rootElementNamespace|schemaType </not> <or> Content: [ and|dtdPublicId|dtdSystemId|fileNameExtension|mimeType| not|or|rootElementLocalName|rootElementNamespace|schemaType ]+ </or> <rootElementLocalName> Content: Name </rootElementLocalName> <rootElementNamespace> Content: anyURI </rootElementNamespace> <schemaType> Content: 'dtd' | 'schema' | 'relaxng' </schemaType>
Register with XXE a condition which can be used to detect the type of a document.
During its start-up, XXE loads all the configuration files it can find, because it needs to keep a list of all detect
elements.
The order of a detect
element in this list depend on the location of its configuration file: configurations loaded from the config
subdirectory of user preferences directory precede configurations loaded from the value of environment variable XXE_ADDON_PATH
which in turn precede configurations loaded from the addon
subdirectory of XXE distribution directory.
When a document is opened, XXE tries each detect
element in turn. If the condition expressed in the detect
element evaluates to true, the detection phase stops and the configuration containing the detect
element is associated to the newly opened document.
Child elements of detect
:
Evaluates to true if all its children evaluate to true.
Evaluates to true if the document has a document type declaration (<!DOCTYPE>
) with a public ID equals to the content of this element.
If substring="true"
, evaluates to true if public ID contains the specified string.
Evaluates to true if the document has a document type declaration (<!DOCTYPE>
) with a system ID equals to the content of this element.
Evaluates to true if the file containing the document has a name which ends with '.
' followed by the content of this element.
Evaluates to true if the file containing the document has a MIME type equals to the content of this element.
Evaluates to true if its child evaluates to false.
Evaluates to true if any of its children evaluates to true.
Evaluates to true if the document has a root element with a local name (name without the namespace part) equals to the content of this element.
Evaluates to true if the document has a root element with a name which belongs to the namespace equals to the content of this element.
Use "<rootElementNamespace xsi:nil='true' />
" to specify that the name of root element has no namespace.
Evaluates to true
if the document is explicitly constrained by a DTD (that is, has a <!DOCTYPE>
) and the content of this element is dtd
,
OR if he document is explicitly constrained by an W3C XML Schema (that is, has a xsi:schemaLocation
or a xsi:noNamespaceSchemaLocation
attribute on its root element) and the content of this element is schema
.
OR if he document is explicitly constrained by RELAX NG schema (that is, contains a <?xxe-relaxng-schema location="..."?> processing instruction) and the content of this element is relaxng
.
Use "<schemaType xsi:nil='true' />
" to specify that document is not explicitly constrained by a DTD, a W3C XML Schema or a RELAX NG schema.
Examples:
Example 7.1. DocBook DTD
<detect> <and> <or> <rootElementLocalName>book</rootElementLocalName> <rootElementLocalName>article</rootElementLocalName> <rootElementLocalName>chapter</rootElementLocalName> <rootElementLocalName>section</rootElementLocalName> <rootElementLocalName>sect1</rootElementLocalName> <rootElementLocalName>sect2</rootElementLocalName> <rootElementLocalName>sect3</rootElementLocalName> <dtdPublicId substring="true">DTD DocBook XML</dtdPublicId> </or> <rootElementNamespace xsi:nil="true" /> <not> <dtdPublicId substring="true">Simplified</dtdPublicId> </not> </and> </detect>
The detect
element in previous example can be described as follows: opened document is a DocBook document if
The local name of the root element is one of book
, article
, chapter
, section
, sect1
, sect2, sect3
.
OR the public ID of its DTD contains string "DTD DocBook XML
".
AND the name of its root element does not belong to any namespace.
AND the public ID of its DTD does not contain string "Simplified
".
Example 7.2. XHTML DTD
<detect> <and> <rootElementNamespace xsi:nil="true" /> <or> <dtdPublicId>-//W3C//DTD XHTML 1.0 Strict//EN</dtdPublicId> <dtdPublicId>-//W3C//DTD XHTML 1.0 Transitional//EN</dtdPublicId> <and> <schemaType xsi:nil="true" /> <or> <rootElementLocalName>body</rootElementLocalName> <rootElementLocalName>div</rootElementLocalName> <rootElementLocalName>html</rootElementLocalName> </or> </and> </or> </and> </detect>
Example 7.3. DocBook RELAX NG
A document conforming to the DocBook DTD is not namespace-aware. A document conforming to the DocBook RELAX NG schema is namespace-aware, but unfortunately this DocBook RELAX NG schema does not use a namespace for DocBook elements. Therefore opened document must have a <?xxe-relaxng-schema location="..."?> processing instruction to make a difference with the DocBook DTD case.
<detect> <and> <schemaType>relaxng</schemaType> <rootElementNamespace xsi:nil="true" /> <or> <rootElementLocalName>book</rootElementLocalName> <rootElementLocalName>article</rootElementLocalName> <rootElementLocalName>chapter</rootElementLocalName> <rootElementLocalName>section</rootElementLocalName> <rootElementLocalName>sect1</rootElementLocalName> <rootElementLocalName>sect2</rootElementLocalName> <rootElementLocalName>sect3</rootElementLocalName> </or> </and> </detect>
Example 7.4. XHTML RELAX NG
A document conforming to the XHTML DTD is not namespace-aware. A document conforming to the XHTML RELAX NG schema is namespace-aware. The rule below uses this specificity to make a difference with the XHTML DTD case.
<detect> <rootElementNamespace>http://www.w3.org/1999/xhtml</rootElementNamespace> </detect>