Invisible XML
BaseX supports the functionality of Invisible XML by making use of Gunther Rademacher’s Markup Blitz implementation. With Invisible XML, text content can be parsed according to a context-free grammar and transformed into XML.
Prerequisites
Updated: Now using Markup Blitz 1.12.
Invisible XML will be available if the Markup Blitz library is found in the classpath. This will be the case if you use the full distributions of BaseX. Alternatively, you can download the library from Maven Central. With BaseX 13.0, use version 1.12, available as markup-blitz-1.12.jar.
Conventions
The namespace prefix ixml, which is used by attributes of Invisible XML result elements, refers to namespace URI http://invisiblexml.org/NS.
Functions
fn:invisible-xml
| Signature | fn:invisible-xml( $grammar as (xs:string | element(ixml))? := (), $options as map(*)? := {}) as fn($value as xs:string) as document-node() | ||||||
|---|---|---|---|---|---|---|---|
| Summary |
The function accepts an Invisible XML If The following
By default, when parsing errors occur, the parsing function returns an element with the attribute |
Result Function
The function that is returned by fn:invisible-xml transforms its input string into an XML structure as specified by the grammar. It returns a document node. The document element may contain an ixml:state attribute, which can include one or more of the following values:
| Value | Description |
|---|---|
failed |
A parsing error has occurred. In this case, the element content provides more details. |
ambiguous |
The input is ambiguous with respect to the grammar. The resulting document represents one valid parse, but others exist. |
version-mismatch |
The grammar prolog requested a specific version of Invisible XML that is not supported. |
If none of the above applies, the ixml:state attribute will be absent.
Example
The following grammar describes a simple arithmetic expression.
Grammar:-expression : term;
add;
subtract.
add : expression, -'+', term.
subtract : expression, -'-', term.
-term : factor;
multiply;
divide.
multiply : term, -'*', factor.
divide : term, -'/', factor.
-factor : integer;
negate;
-'+', factor;
-'(', expression, -')'.
negate : -'-', factor.
integer : @value.
value : (-'+'; '-')?, ['0'-'9']+.
The result is a structured representation of the expression that preserves the precedence of arithmetic operators.
Query:invisible-xml($grammar)("3*13+3")
Result:
<add>
<multiply>
<integer value="3"/>
<integer value="13"/>
</multiply>
<integer value="3"/>
</add>
The grammar is ambiguous, because it allows plus and minus signs in both the factor and the value rule. A double minus sign preceding a value can thus be interpreted as two negations of a positive integer, or one negation of a negative integer. The parser will return one of these interpretations and indicate the result as ambiguous in the ixml:state attribute.
invisible-xml($grammar)("--1")
Result:
<negate xmlns:ixml="http://invisiblexml.org/NS" ixml:state="ambiguous">
<integer value="-1"/>
</negate>
Changelog
Version 13.0- Updated: Now using Markup Blitz 1.12.
- Updated: Argument
$grammarcan alternatively be passed in XML representation.
- Added: Full support for Invisible XML, utilizing Gunther Rademacher’s Markup Blitz implementation.