org.libxmq
The Java
api.
Parse xmq, xml, html and json into a DOM and query it with xpath, from Java. This page is generated from the Java sources: each file is parsed with the ixml grammar ixml:lang/java, where /** ... */ is a javadoc element, and transformed with an xslq stylesheet.
scripts/generate_java_api_doc.sh
Examples:LoadConfigFile.java CreateDom.java CreateHtml.java CreateJson.java DefaultNamespace.java NamespacePrefixes.java AddNamespace.java GeneratedPrefixes.java ParseWithIxml.java LinePrintf.java
XMQ
public class XMQ
The XMQ class is used to parse/print/render XMQ/XML/HTML/JSON documents.
XMQ()Construct an XMQ using the xmq DOM implementation.
public XMQ();
Construct an XMQ using the xmq DOM implementation.
parseFile(Path, InputSettings)Parse a file containing XMQ/XML/HTML/JSON/CLINES.
public XmlDocument parseFile(Path file, InputSettings is) throws IOException, ParseException;
Parse a file containing XMQ/XML/HTML/JSON/CLINES.
Parameters
file- The file to parse.
is- The input settings, should white space be trimmed, should text nodes be merged etc.
Returns
- A DOM document.
Throws
IOException- if file cannot be read.
ParseException- if the parse failed.
parseBuffer(String, InputSettings)Parse a buffer containing XMQ/XML/HTML/JSON/CLINES.
public XmlDocument parseBuffer(String buffer, InputSettings is) throws ParseException;
Parse a buffer containing XMQ/XML/HTML/JSON/CLINES.
Parameters
buffer- The string to parse.
is- The input settings, should white space be trimmed, should text nodes be merged etc.
Returns
- A DOM document.
Throws
ParseException- if the parse failed.
queryFile(Path, InputSettings)Parse a file containing XMQ/XML/HTML/JSON/CLINES and return a Query object to the DOM.
public Query queryFile(Path file, InputSettings is) throws IOException, ParseException;
Parse a file containing XMQ/XML/HTML/JSON/CLINES and return a Query object to the DOM.
Parameters
file- The file to parse.
is- The input settings, should white space be trimmed, should text nodes be merged etc.
Returns
- A Query object.
Throws
IOException- if file cannot be read.
ParseException- if the parse failed.
queryBuffer(String, InputSettings)Parse a buffer containing XMQ/XML/HTML/JSON/CLINES and return a Query object for the DOM.
public Query queryBuffer(String buffer, InputSettings is) throws ParseException;
Parse a buffer containing XMQ/XML/HTML/JSON/CLINES and return a Query object for the DOM.
Parameters
buffer- The string to parse.
is- The input settings, should white space be trimmed, should text nodes be merged etc.
Returns
- A Query object.
Throws
ParseException- if the parse failed.
newDoc()Create a new empty document, like xmqNewDoc.
public XmlDocument newDoc();
Create a new empty document, like xmqNewDoc.
Returns
- The document.
setDocType(XmlDocument, String)Set the doctype of the document, eg html, like xmqSetDocType.
public void setDocType(XmlDocument doc, String name);
Set the doctype of the document, eg html, like xmqSetDocType.
Parameters
doc- The document.
name- The doctype name.
addRootElement(XmlDocument, String, NS)Add the root element to the document, like xmqAddRootElement.
public XmlElement addRootElement(XmlDocument doc, String name, NS ns);
Add the root element to the document, like xmqAddRootElement.
Parameters
doc- The document.
name- The element name.
ns- The namespace, NS.NONE or NS.here(uri). NS.PARENT is the same as NS.NONE here.
Returns
- The root element.
Throws
IllegalArgumentException- if the namespace is invalid.
addNamespace(XmlElement, NS)Declare a namespace with a prefix on an element, without using it for the element itself, like xmqAddNamespace.
public void addNamespace(XmlElement element, NS ns);
Declare a namespace with a prefix on an element, without using it for the element itself, like xmqAddNamespace. Use it in children with NS.ancestor(uri).
Parameters
element- The element.
ns- The namespace, NS.here("{prefix}uri"), the prefix is required.
Throws
IllegalArgumentException- if the namespace is not NS.here with a prefix, or if the prefix is already declared on the element for another uri.
addElement(XmlElement, String, NS)Add an element as the last child of parent, like xmqAddElement.
public XmlElement addElement(XmlElement parent, String name, NS ns);
Add an element as the last child of parent, like xmqAddElement.
Parameters
parent- The parent element.
name- The element name.
ns- The namespace, NS.NONE, NS.PARENT, NS.here(uri) or NS.ancestor(uri).
Returns
- The new element.
Throws
IllegalArgumentException- if the namespace is invalid.
addElementWithAttrs(XmlElement, String, NS, String...)Add an element with attributes, like xmqAddElementWithAttrs.
public XmlElement addElementWithAttrs(XmlElement parent, String name, NS ns, String... attrs);
Add an element with attributes, like xmqAddElementWithAttrs.
Parameters
parent- The parent element.
name- The element name.
ns- The namespace, see addElement.
attrs- The attributes as name, value pairs, eg "href", "https://libxmq.org".
Returns
- The new element.
addKeyValue(XmlElement, String, String, NS)Add an element with a text value, key=value in xmq, like xmqAddKeyValue.
public XmlElement addKeyValue(XmlElement parent, String key, String value, NS ns);
Add an element with a text value, key=value in xmq, like xmqAddKeyValue.
Parameters
parent- The parent element.
key- The element name.
value- The text, an empty or null value gives an empty element.
ns- The namespace, see addElement.
Returns
- The new element.
addKeyValueWithAttrs(XmlElement, String, String, NS, String...)Add an element with a text value and attributes, like xmqAddKeyValueWithAttrs.
public XmlElement addKeyValueWithAttrs(XmlElement parent, String key, String value, NS ns, String... attrs);
Add an element with a text value and attributes, like xmqAddKeyValueWithAttrs.
Parameters
parent- The parent element.
key- The element name.
value- The text.
ns- The namespace, see addElement.
attrs- The attributes as name, value pairs.
Returns
- The new element.
compileIXML(String)Compile an ixml grammar, to parse inputs with parseBufferWithIXML.
public IXML compileIXML(String grammar) throws ParseException;
Compile an ixml grammar, to parse inputs with parseBufferWithIXML. Like parsing the grammar with xmqParseBufferWithType and XMQ_CONTENT_IXML.
Parameters
grammar- The ixml grammar source.
Returns
- The compiled grammar.
Throws
ParseException- if the grammar has a syntax error.
parseBufferWithIXML(String, IXML)Parse a buffer with an ixml grammar, like xmqParseBufferWithIXML.
public XmlDocument parseBufferWithIXML(String buffer, IXML ixml) throws ParseException;
Parse a buffer with an ixml grammar, like xmqParseBufferWithIXML.
Parameters
buffer- The input to parse.
ixml- The compiled grammar.
Returns
- The parse tree.
Throws
ParseException- if the input is rejected by the grammar.
parseBufferWithIXML(byte[], IXML)Parse an UTF-8 buffer with an ixml grammar, like xmqParseBufferWithIXML.
public XmlDocument parseBufferWithIXML(byte[] buffer, IXML ixml) throws ParseException;
Parse an UTF-8 buffer with an ixml grammar, like xmqParseBufferWithIXML. The Earley parser decodes the code points directly from the bytes.
Parameters
buffer- The input to parse, UTF-8.
ixml- The compiled grammar.
Returns
- The parse tree.
Throws
ParseException- if the input is rejected by the grammar, or is not valid UTF-8.
compactQuote(String)Quote a value as xmq on a single line, eg 'car go' or ('howdy'
'dowdy'), like xmqCompactQuote.
public String compactQuote(String content);
Quote a value as xmq on a single line, eg 'car go' or ('howdy'
'dowdy'), like xmqCompactQuote.
Parameters
content- The value.
Returns
- The quoted value.
toXMQ(Object, OutputSettings)Print the document as XMQ.
public String toXMQ(Object doc, OutputSettings os);
Print the document as XMQ.
Parameters
doc- Document to print.
os- Settings for printing.
Returns
- A string with XMQ.
toXML(Object, OutputSettings)Print the document as XML.
public String toXML(Object doc, OutputSettings os);
Print the document as XML. This means that the argument doc is assumed to store an XML document. By printing it as XML the document will follow the XML rules.
Parameters
doc- Document to print.
os- Settings for printing.
Returns
- A string with XML.
toHTML(Object, OutputSettings)Print the document as HTML.
public String toHTML(Object doc, OutputSettings os);
Print the document as HTML. This means that the argument doc is assumed to store a HTML document. By printing it as HTML the document will follow the HTML rules (using self closing tags like <br> and potentially using HTML entities like &nbsp;)
Parameters
doc- Document to print.
os- Settings for printing.
Returns
- A string with HTML.
toJSON(Object, OutputSettings)Print the document as json.
public String toJSON(Object doc, OutputSettings os);
Print the document as json.
Parameters
doc- Document to print.
os- Settings for printing.
Returns
- A string with JSON.
toCLINES(Object, OutputSettings)Print the document as clines.
public String toCLINES(Object doc, OutputSettings os);
Print the document as clines.
Parameters
doc- Document to print.
os- Settings for printing.
Returns
- A string with clines.
renderHTML(Object, OutputSettings)Render the document as XMQ in HTML.
public String renderHTML(Object doc, OutputSettings os);
Render the document as XMQ in HTML. I.e. build a new HTML document that when viewed in a browser makes it easy to read the XMQ.
Parameters
doc- Document to render
os- Settings for rendering
Returns
- A string with HTML.
renderTEX(Object, OutputSettings)Render the document as XMQ in TeX.
public String renderTEX(Object doc, OutputSettings os);
Render the document as XMQ in TeX. When the TeX document is rendered using for example xetex/xelatex, it will generate a pdf containing the human readable XMQ.
Parameters
doc- Document to render
os- Settings for rendering
Returns
- A string with TeX commands.
printException(ParseException, Locale)Render a locale adapted text cli error printout of a parse exception.
public static String printException(ParseException e, Locale locale);
Render a locale adapted text cli error printout of a parse exception.
Parameters
e- The parse exception.
locale- The locale to use.
Returns
- A string to be printed on the console.
printException(ParseException)Render a locale adapted text cli error printout of a parse exception using the default locale.
public static String printException(ParseException e);
Render a locale adapted text cli error printout of a parse exception using the default locale.
Parameters
e- The parse exception.
Returns
- A string to be printed on the console.
DecodingException
public class DecodingException extends Exception
The DecodingException is thrown when a query failes to decode the text retrieved from the Document into the desired type.
DecodingException(String, String, String)Construct a decoding exception.
public DecodingException(String type, String restriction, String value);
Construct a decoding exception.
Parameters
type- The name of the desired type.
restriction- The type restriction, if any.
value- The value which could not be decoded.
IXML
public final class IXML
A compiled ixml grammar, used to parse many inputs, see XMQ.compileIXML and XMQ.parseBufferWithIXML. Like an XMQDoc parsed with XMQ_CONTENT_IXML in xmq.h. A grammar that is LL(*) is parsed with the fast predictive parser, any other grammar with the Earley parser.
compile(String)Compile an ixml grammar.
public static IXML compile(String grammar) throws ParseException;
Compile an ixml grammar.
Parameters
grammar- The ixml grammar source.
Returns
- The compiled grammar.
Throws
ParseException- if the grammar has a syntax error.
source()The ixml grammar source.
public String source();
The ixml grammar source.
Returns
- The source.
parse(String)Parse an input with the grammar.
public XmlDocument parse(String input) throws ParseException;
Parse an input with the grammar.
Parameters
input- The input to parse.
Returns
- The parse tree.
Throws
ParseException- if the input is rejected by the grammar.
parse(byte[])Parse an UTF-8 input with the grammar.
public XmlDocument parse(byte[] input) throws ParseException;
Parse an UTF-8 input with the grammar. The Earley parser decodes the code points directly from the bytes, the input is not copied into a String.
Parameters
input- The input to parse, UTF-8.
Returns
- The parse tree.
Throws
ParseException- if the input is rejected by the grammar, or is not valid UTF-8.
parse(byte[], int, int)Parse an UTF-8 input with the grammar, the bytes start to stop of the buffer.
public XmlDocument parse(byte[] buf, int start, int stop) throws ParseException;
Parse an UTF-8 input with the grammar, the bytes start to stop of the buffer.
Parameters
buf- The buffer with the input, UTF-8.
start- The first byte of the input.
stop- The end of the input, exclusive.
Returns
- The parse tree.
Throws
ParseException- if the input is rejected by the grammar, or is not valid UTF-8.
InputSettings
public class InputSettings
Used to configure the parser behaviour when parsing XMQ. Example: InputSettings is = new InputSettings().setImplicitRoot("config").setTrimNone();
InputSettings()Construct an default input settings.
public InputSettings();
Construct an default input settings.
setImplicitRoot(String)Set the implicit root when parsing XMQ.
public InputSettings setImplicitRoot(String r);
Set the implicit root when parsing XMQ. Normally XML requires an explicit root element. However when loading an expected configuration file in XMQ the root can be explicit (eg "config"). This means that an XMQ config file can be as simple as a list of key=value pairs. Example: speed=123
type=car
Parameters
r- The implicit root to add, eg "config".
Returns
- this
InputSettingsinstance, for method chaining
getImplicitRoot()Returns the previously set trim none.
public String getImplicitRoot();
Returns the previously set trim none.
Returns
- the trim none status
setTrimNone(boolean)Disable whitespace trimming using the xmq heuristic when loading xml/html.
public InputSettings setTrimNone(boolean b);
Disable whitespace trimming using the xmq heuristic when loading xml/html.
Parameters
b- True means keep all whitespace as-is.
Returns
- this
OutputSettingsinstance, for method chaining
getTrimNone()Returns the previously set trim none.
public boolean getTrimNone();
Returns the previously set trim none.
Returns
- the trim none status
setNoMerge(boolean)Disable automatic merging of text noes when loading document.
public InputSettings setNoMerge(boolean b);
Disable automatic merging of text noes when loading document.
Parameters
b- True means keep text nodes separate when loading from xmq.
Returns
- this
OutputSettingsinstance, for method chaining
getNoMerge()Returns the previously set no merge.
public boolean getNoMerge();
Returns the previously set no merge.
Returns
- the no merge status
LineConfig
public class LineConfig
Print log lines as xmq, like xmqLinePrintf in xmq.h. LineConfig lc = new LineConfig();
lc.printf("car{", "nw=", "%d", 36, "model=", "%s", "car go", "}"); // car{nw=36 model='car go'}
lc.printf("work=", "pi is %f", 3.14159); // work='pi is 3.141590'
lc.printf("Fix me!"); // log='Fix me!'
lc.setHumanReadable(true);
lc.printf("work=", "pi is %f", 3.14159); // (work) pi is 3.141590
After an element name ending with { follows a key ending with =, a format and the arguments the format uses, repeated, and finally "}". The formats are java formats (String.format, with Locale.ROOT like C printf), the values are quoted as needed.
LineConfig()Create a line config that prints xmq.
public LineConfig();
Create a line config that prints xmq.
setHumanReadable(boolean)Print human readable lines instead of xmq, eg (work) pi is 3.141590.
public LineConfig setHumanReadable(boolean enabled);
Print human readable lines instead of xmq, eg (work) pi is 3.141590.
Parameters
enabled- True for human readable lines.
Returns
- This line config.
humanReadable()Is the output human readable?
public boolean humanReadable();
Is the output human readable?
Returns
- True if human readable.
printf(String, Object...)Print a line.
public String printf(String element_name, Object... args);
Print a line.
Parameters
element_name- The element name, ending with { for keys and values, with = for a single value, otherwise it is the text to log.
args- The keys, formats and arguments.
Returns
- The line.
Throws
IllegalArgumentException- if a key does not end with =.
NS
public final class NS
The namespace of an element added with XMQ.addElement etc, like XMQNS in xmq.h. The uri can be prefixed with {prefix}, eg NS.here("{drv}urn:myapp:driver"). NS.NONE No namespace.
NS.PARENT The same namespace as the parent.
NS.here(uri) Declare the namespace on the element.
NS.ancestor(uri) Use the namespace declared on an ancestor. If no ancestor
declares it, it is declared on the root element, with a
generated prefix ns1, ns2... if no prefix is given.
NONENo namespace, like NS_NONE.
public static final NS NONE;
No namespace, like NS_NONE.
PARENTThe same namespace as the parent, like NS_PARENT.
public static final NS PARENT;
The same namespace as the parent, like NS_PARENT.
here(String)Declare the namespace on the element, like NS_HERE.
public static NS here(String uri);
Declare the namespace on the element, like NS_HERE.
Parameters
uri- The namespace uri, eg urn:cargo or {c}urn:cargo for the prefix c.
Returns
- The namespace.
ancestor(String)Use the namespace declared on an ancestor, like NS_ANCESTOR.
public static NS ancestor(String uri);
Use the namespace declared on an ancestor, like NS_ANCESTOR.
Parameters
uri- The namespace uri, eg urn:cargo or {c}urn:cargo for the prefix c.
Returns
- The namespace.
NodeCallback
public interface NodeCallback
A functional interface used to call back for each found DOM node.
invoke(XmlNode)Invoked for each node found.
Proceed invoke(XmlNode node);
Invoked for each node found.
Parameters
node- The node currently iterating over.
Returns
- Wether to proceed or stop.
NotFoundException
public class NotFoundException extends Exception
The not found exception is thrown when a query cannot find the desired value to decode and return.
NotFoundException(String)Construct a not found exception.
public NotFoundException(String path);
Construct a not found exception.
Parameters
path- The path into the document for which no value was found.
OutputSettings
public class OutputSettings
The
OutputSettings class is used to configure the output behavior when printing XMQ. It provides options for controlling pretty printing, indentation, and other formatting settings that affect how XMQ content is presented as plain text, ansi-colored text, HTML or TeX. Typical usage involves enabling or disabling pretty printing, setting the indentation width, and adjusting other output-related preferences to produce human-readable or compact XMQ output. Example: OutputSettings settings = new OutputSettings()
.setPrettyPrint(true)
.setIndentAmount(4);
OutputSettings()Create default output settings.
public OutputSettings();
Create default output settings.
setCompact(boolean)Set if printing compact XMQ or not.
public OutputSettings setCompact(boolean c);
Set if printing compact XMQ or not. Compact XMQ uses no newlines for the entire document.
Parameters
c- If true, then print XMQ on a single line, ie no newlines.
Returns
- this
OutputSettingsinstance, for method chaining
compact()Returns the previously set compact setting.
public boolean compact();
Returns the previously set compact setting.
Returns
- the compact setting
setIndentAmount(int)Sets the number of spaces to use for each level of indentation when pretty printing XMQ output.
public OutputSettings setIndentAmount(int amount);
Sets the number of spaces to use for each level of indentation when pretty printing XMQ output. This setting is only applied when pretty printing is enabled. Increasing the indent amount makes the output more readable, while setting a smaller value produces more compact output.
Parameters
amount- the number of spaces to use per indentation level; must be zero or a positive integer, negative values are interpreted as zero.
Returns
- this
OutputSettingsinstance, for method chaining
indentAmount()Returns the previously set indentation amount.
public int indentAmount();
Returns the previously set indentation amount.
Returns
- the indentation amount
setEscapeTabs(boolean)Set if tabs in text should be printed as a 	 entity instead of a literal tab (the --escape-tabs option).
public OutputSettings setEscapeTabs(boolean e);
Set if tabs in text should be printed as a
	 entity instead of a literal tab (the --escape-tabs option). Parameters
e- If true, then escape tabs as entities.
Returns
- this
OutputSettingsinstance, for method chaining
escapeTabs()Returns the previously set escape-tabs setting.
public boolean escapeTabs();
Returns the previously set escape-tabs setting.
Returns
- the escape-tabs setting
setEscapeNewlines(boolean)Set if newlines in text should be printed as a entity instead of a literal newline (the --escape-newlines option).
public OutputSettings setEscapeNewlines(boolean e);
Set if newlines in text should be printed as a
entity instead of a literal newline (the --escape-newlines option). Parameters
e- If true, then escape newlines as entities.
Returns
- this
OutputSettingsinstance, for method chaining
escapeNewlines()Returns the previously set escape-newlines setting.
public boolean escapeNewlines();
Returns the previously set escape-newlines setting.
Returns
- the escape-newlines setting
setEscapeNon7bit(boolean)Set if non 7bit characters should be printed as an entity (the --escape-non-7bit option).
public OutputSettings setEscapeNon7bit(boolean e);
Set if non 7bit characters should be printed as an entity (the
--escape-non-7bit option). Parameters
e- If true, then escape non 7-bit characters as entities.
Returns
- this
OutputSettingsinstance, for method chaining
setHtmq(boolean)Set if the output format is htmq.
public OutputSettings setHtmq(boolean h);
Set if the output format is htmq. Then non 7-bit characters are escaped using html entity names, when such a name exists.
Parameters
h- If true, the output is htmq.
Returns
- this
OutputSettingsinstance, for method chaining
htmq()Returns true if the output format is htmq.
public boolean htmq();
Returns true if the output format is htmq.
Returns
- the htmq setting
escapeNon7bit()Returns the previously set escape-non-7bit setting.
public boolean escapeNon7bit();
Returns the previously set escape-non-7bit setting.
Returns
- the escape-non-7bit setting
setPreferDoubleQuotes(boolean)Set if double quotes should be preferred over single quotes (the --prefer-double-quotes option).
public OutputSettings setPreferDoubleQuotes(boolean p);
Set if double quotes should be preferred over single quotes (the
--prefer-double-quotes option). Parameters
p- If true, then prefer double quotes.
Returns
- this
OutputSettingsinstance, for method chaining
preferDoubleQuotes()Returns the previously set prefer-double-quotes setting.
public boolean preferDoubleQuotes();
Returns the previously set prefer-double-quotes setting.
Returns
- the prefer-double-quotes setting
setNoTrim(boolean)Set if the text of the document should not be trimmed (the --trim=none option).
public OutputSettings setNoTrim(boolean n);
Set if the text of the document should not be trimmed (the
--trim=none option). Parameters
n- If true, then do not trim leading and trailing whitespace from text at parse time.
Returns
- this
OutputSettingsinstance, for method chaining
noTrim()Returns the previously set no-trim setting.
public boolean noTrim();
Returns the previously set no-trim setting.
Returns
- the no-trim setting
ParseErrorCode
public enum ParseErrorCode
These are the potential parse errors that can be returned from libxmq.
XMQ_ERROR_NONENo error.
ParseErrorCode.XMQ_ERROR_NONE
No error.
XMQ_ERROR_CANNOT_READ_FILECannot read file.
ParseErrorCode.XMQ_ERROR_CANNOT_READ_FILE
Cannot read file.
XMQ_ERROR_OOMOut of memory.
ParseErrorCode.XMQ_ERROR_OOM
Out of memory.
XMQ_ERROR_NOT_XMQNot XMQ.
ParseErrorCode.XMQ_ERROR_NOT_XMQ
Not XMQ.
XMQ_ERROR_QUOTE_NOT_CLOSEDQuote not closed.
ParseErrorCode.XMQ_ERROR_QUOTE_NOT_CLOSED
Quote not closed.
XMQ_ERROR_ENTITY_NOT_CLOSEDEntity not closed.
ParseErrorCode.XMQ_ERROR_ENTITY_NOT_CLOSED
Entity not closed.
XMQ_ERROR_COMMENT_NOT_CLOSEDComment not closed.
ParseErrorCode.XMQ_ERROR_COMMENT_NOT_CLOSED
Comment not closed.
XMQ_ERROR_COMMENT_CLOSED_WITH_TOO_MANY_SLASHESComment closed with too many slashes.
ParseErrorCode.XMQ_ERROR_COMMENT_CLOSED_WITH_TOO_MANY_SLASHES
Comment closed with too many slashes.
XMQ_ERROR_BODY_NOT_CLOSEDBody not closed.
ParseErrorCode.XMQ_ERROR_BODY_NOT_CLOSED
Body not closed.
XMQ_ERROR_ATTRIBUTES_NOT_CLOSEDAttributes not closed.
ParseErrorCode.XMQ_ERROR_ATTRIBUTES_NOT_CLOSED
Attributes not closed.
XMQ_ERROR_COMPOUND_NOT_CLOSEDCompound not closed.
ParseErrorCode.XMQ_ERROR_COMPOUND_NOT_CLOSED
Compound not closed.
XMQ_ERROR_COMPOUND_MAY_NOT_CONTAINCompound may not contain.
ParseErrorCode.XMQ_ERROR_COMPOUND_MAY_NOT_CONTAIN
Compound may not contain.
XMQ_ERROR_QUOTE_CLOSED_WITH_TOO_MANY_QUOTESQuote closed with too many quotes.
ParseErrorCode.XMQ_ERROR_QUOTE_CLOSED_WITH_TOO_MANY_QUOTES
Quote closed with too many quotes.
XMQ_ERROR_UNEXPECTED_CLOSING_BRACEUnexpected closing brace.
ParseErrorCode.XMQ_ERROR_UNEXPECTED_CLOSING_BRACE
Unexpected closing brace.
XMQ_ERROR_EXPECTED_CONTENT_AFTER_EQUALSExpected content after equals.
ParseErrorCode.XMQ_ERROR_EXPECTED_CONTENT_AFTER_EQUALS
Expected content after equals.
XMQ_ERROR_UNEXPECTED_TABUnexpected tab.
ParseErrorCode.XMQ_ERROR_UNEXPECTED_TAB
Unexpected tab.
XMQ_ERROR_INVALID_CHARInvalid char.
ParseErrorCode.XMQ_ERROR_INVALID_CHAR
Invalid char.
XMQ_ERROR_BAD_DOCTYPEBad doctype.
ParseErrorCode.XMQ_ERROR_BAD_DOCTYPE
Bad doctype.
XMQ_ERROR_JSON_INVALID_ESCAPEJSON invalid escape.
ParseErrorCode.XMQ_ERROR_JSON_INVALID_ESCAPE
JSON invalid escape.
XMQ_ERROR_JSON_INVALID_CHARJSON invalid char.
ParseErrorCode.XMQ_ERROR_JSON_INVALID_CHAR
JSON invalid char.
XMQ_ERROR_CANNOT_HANDLE_XMLCannot handle XML.
ParseErrorCode.XMQ_ERROR_CANNOT_HANDLE_XML
Cannot handle XML.
XMQ_ERROR_CANNOT_HANDLE_HTMLCannot handle HTML.
ParseErrorCode.XMQ_ERROR_CANNOT_HANDLE_HTML
Cannot handle HTML.
XMQ_ERROR_CANNOT_HANDLE_JSONCannot handle JSON.
ParseErrorCode.XMQ_ERROR_CANNOT_HANDLE_JSON
Cannot handle JSON.
XMQ_ERROR_EXPECTED_XMQExpected XMQ.
ParseErrorCode.XMQ_ERROR_EXPECTED_XMQ
Expected XMQ.
XMQ_ERROR_EXPECTED_HTMQExpected HTMQ.
ParseErrorCode.XMQ_ERROR_EXPECTED_HTMQ
Expected HTMQ.
XMQ_ERROR_EXPECTED_XMLExpected XML.
ParseErrorCode.XMQ_ERROR_EXPECTED_XML
Expected XML.
XMQ_ERROR_EXPECTED_HTMLExpected HTML.
ParseErrorCode.XMQ_ERROR_EXPECTED_HTML
Expected HTML.
XMQ_ERROR_EXPECTED_JSONExpected JSON.
ParseErrorCode.XMQ_ERROR_EXPECTED_JSON
Expected JSON.
XMQ_ERROR_PARSING_XMLError parsing XML.
ParseErrorCode.XMQ_ERROR_PARSING_XML
Error parsing XML.
XMQ_ERROR_PARSING_HTMLError parsing HTML.
ParseErrorCode.XMQ_ERROR_PARSING_HTML
Error parsing HTML.
XMQ_ERROR_VALUE_CANNOT_START_WITHValue cannot start with.
ParseErrorCode.XMQ_ERROR_VALUE_CANNOT_START_WITH
Value cannot start with.
XMQ_ERROR_XML_FRAGMENT_NOT_CLOSEDEmbedded xml fragment is not closed.
ParseErrorCode.XMQ_ERROR_XML_FRAGMENT_NOT_CLOSED
Embedded xml fragment is not closed.
XMQ_ERROR_INVALID_UTF8The input is not valid UTF-8.
ParseErrorCode.XMQ_ERROR_INVALID_UTF8
The input is not valid UTF-8.
XMQ_ERROR_TOO_DEEPThe elements, objects or arrays are nested deeper than XMQParser.MAX_NESTING_DEPTH.
ParseErrorCode.XMQ_ERROR_TOO_DEEP
The elements, objects or arrays are nested deeper than XMQParser.MAX_NESTING_DEPTH.
XMQ_ERROR_IXML_EXPECTED_RULEIXML expected rule.
ParseErrorCode.XMQ_ERROR_IXML_EXPECTED_RULE
IXML expected rule.
XMQ_ERROR_IXML_EXPECTED_NAMEIXML expected name.
ParseErrorCode.XMQ_ERROR_IXML_EXPECTED_NAME
IXML expected name.
XMQ_ERROR_IXML_EXPECTED_EQUAL_OR_COLONIXML expected equal or colon.
ParseErrorCode.XMQ_ERROR_IXML_EXPECTED_EQUAL_OR_COLON
IXML expected equal or colon.
XMQ_ERROR_IXML_EXPECTED_DOTIXML expected dot.
ParseErrorCode.XMQ_ERROR_IXML_EXPECTED_DOT
IXML expected dot.
XMQ_ERROR_IXML_UNEXPECTED_ENDIXML unexpected end.
ParseErrorCode.XMQ_ERROR_IXML_UNEXPECTED_END
IXML unexpected end.
XMQ_ERROR_IXML_SYNTAX_ERRORIXML syntax error.
ParseErrorCode.XMQ_ERROR_IXML_SYNTAX_ERROR
IXML syntax error.
XMQ_WARNING_QUOTES_NEEDEDWarning quotes needed.
ParseErrorCode.XMQ_WARNING_QUOTES_NEEDED
Warning quotes needed.
valueReturn error code.
public int value;
Return error code.
ParseException
public class ParseException extends Exception
The parse exception contains necessary information to understand the parse failure.
ParseException(ParseErrorCode, String, int, int, String)Construct a parse exception.
public ParseException(ParseErrorCode ec, String text, int line, int column, String source);
Construct a parse exception.
Parameters
ec- The error code.
text- The line on which the parse failed.
line- The line number.
column- The column.
source- Information about where the xmq originated from.
ParseException(ParseErrorCode, String, int, int, String, String, int)Construct a parse exception with extra information, like the C error_info, where the offending char is not at the column (as in the yaml parser).
public ParseException(ParseErrorCode ec, String text, int line, int column, String source, String info, int char_index);
Construct a parse exception with extra information, like the C error_info, where the offending char is not at the column (as in the yaml parser).
Parameters
ec- The error code.
text- The line on which the parse failed.
line- The line number.
column- The column that is reported.
source- Information about where the xmq originated from.
info- Extra information appended to the message, or null.
char_index- The position of the offending char in text, -1 if at the end of the input.
info()Get the extra information, or null.
public String info();
Get the extra information, or null.
Returns
- the information
charIndex()Get the position of the offending char in the text, -1 if at the end of the input.
public int charIndex();
Get the position of the offending char in the text, -1 if at the end of the input.
Returns
- the position
errorCode()Get the error code.
text()Get the line of text.
public String text();
Get the line of text.
Returns
- line of text
line()Get the line number.
public int line();
Get the line number.
Returns
- line number
column()Get the column.
public int column();
Get the column.
Returns
- column
source()Get the source, ie file name, "mbuffer", "stdin" etc.
public String source();
Get the source, ie file name, "mbuffer", "stdin" etc.
Returns
- The source information.
Proceed
public enum Proceed
Used when iterating over found DOM nodes.
CONTINUEReturn CONTINUE from invoke in the node callback, to keep iterating.
Proceed.CONTINUE
Return CONTINUE from invoke in the node callback, to keep iterating.
STOPReturn STOP from invoke in the node callback, to stop itering.
Proceed.STOP
Return STOP from invoke in the node callback, to stop itering.
Query
public class Query
The Query class implemets the basic querying methods.
Query(Object)Build a new query from a DOM node.
public Query(Object node);
Build a new query from a DOM node.
Parameters
node- The DOM node from which the paths start when querying.
node()Return the node from which the query starts.
public Object node();
Return the node from which the query starts.
Returns
- A DOM node.
forEach(String, NodeCallback)Perform a callback for each node matching the xpath expression.
public int forEach(String xpath, NodeCallback cb);
Perform a callback for each node matching the xpath expression.
Parameters
xpath- An xpath, for example: //book
cb- The callback function.
Returns
- The number of nodes matched.
expect(String, NodeCallback)Perform a single callback for a single node matching the xpath expression.
public void expect(String xpath, NodeCallback cb) throws NotFoundException;
Perform a single callback for a single node matching the xpath expression.
Parameters
xpath- An xpath that is assumed to match only a single , for example: /library
cb- The callback function.
Throws
NotFoundException- if the expected xpath was not found.
element(String)Fetches a single element from the xpath.
public XmlElement element(String xpath) throws NotFoundException, TooManyException;
Fetches a single element from the xpath.
Parameters
xpath- An xpath that is assumed to match only a single , for example: /library
Returns
- The found element.
Throws
NotFoundException- if the expected xpath was not found.
TooManyException- if more than one element matched the xpath.
optionalElement(String)Fetches a single optional element from the xpath.
public Optional<XmlElement> optionalElement(String xpath) throws TooManyException;
Fetches a single optional element from the xpath.
Parameters
xpath- An xpath that is assumed to match only a single , for example: /library
Returns
- The found element.
Throws
TooManyException- if more than one element matched the xpath.
getBoolean(String)Get a boolean from an xpath location.
public boolean getBoolean(String xpath) throws DecodingException, NotFoundException, TooManyException;
Get a boolean from an xpath location. Two strings are valid 'true' and 'false'. Anything else will throw a DecodingException.
Parameters
xpath- An xpath that is used to find the boolean.
Returns
- The boolean.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not 'true' or 'false'.
TooManyException- if more than one element matched the xpath.
getOptionalBoolean(String)Get an optional boolean from an xpath location.
public Optional<Boolean> getOptionalBoolean(String xpath) throws DecodingException, TooManyException;
Get an optional boolean from an xpath location. Two strings are valid 'true' and 'false'. Anything else will throw a DecodingException.
Parameters
xpath- An xpath that finds the desired boolean.
Returns
- The optional boolean.
Throws
DecodingException- if the value was not 'true' or 'false'.
TooManyException- if more than one element matched the xpath.
getDouble(String, String)Get a 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
public double getDouble(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException;
Get a 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- A double value.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getOptionalDouble(String, String)Get an optional 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
public Optional<Double> getOptionalDouble(String xpath, String restriction) throws DecodingException, TooManyException;
Get an optional 64 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- A double value.
Throws
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getFloat(String, String)Get a 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
public float getFloat(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException;
Get a 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- The float found.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getOptionalFloat(String, String)Get an optional 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
public Optional<Float> getOptionalFloat(String xpath, String restriction) throws DecodingException, TooManyException;
Get an optional 32 bit IEEE double floating point value from an xpath location and check that it complies with the restrictions.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- The float found.
Throws
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getInt(String, String)Get a 32 bit signed integer from an xpath location and check that it complies with the restriction.
public int getInt(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException;
Get a 32 bit signed integer from an xpath location and check that it complies with the restriction.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- The integer.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer.
TooManyException- if more than one element matched the xpath.
getOptionalInt(String, String)Get an optional 32 bit signed integer from an xpath location and check that it complies with the restriction.
public Optional<Integer> getOptionalInt(String xpath, String restriction) throws DecodingException, TooManyException;
Get an optional 32 bit signed integer from an xpath location and check that it complies with the restriction.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- The integer.
Throws
DecodingException- if the value was not an integer.
TooManyException- if more than one element matched the xpath.
getLong(String, String)Get a 64 bit signed integer from an xpath location that complies with any restriction.
public long getLong(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException;
Get a 64 bit signed integer from an xpath location that complies with any restriction.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- The found long.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not a long integer.
TooManyException- if more than one element matched the xpath.
getOptionalLong(String, String)Get an optional 64 bit signed integer from an xpath location that complies with any restriction.
public Optional<Long> getOptionalLong(String xpath, String restriction) throws DecodingException, TooManyException;
Get an optional 64 bit signed integer from an xpath location that complies with any restriction.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The float can for example be restricted in range.
Returns
- The found long.
Throws
DecodingException- if the value was not a long integer.
TooManyException- if more than one element matched the xpath.
getString(String, String)Get a string from an xpath location that complies with a restriction.
public String getString(String xpath, String restriction) throws DecodingException, NotFoundException, TooManyException;
Get a string from an xpath location that complies with a restriction.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The value can for example be restricted.
Returns
- The found string.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value failed the restriction.
TooManyException- if more than one element matched the xpath.
getOptionalString(String, String)Get an optional string from an xpath location that complies with a restriction.
public Optional<String> getOptionalString(String xpath, String restriction) throws DecodingException, TooManyException;
Get an optional string from an xpath location that complies with a restriction.
Parameters
xpath- Fetch the value found using this xpath.
restriction- The value can for example be restricted.
Returns
- The found string.
Throws
DecodingException- if the value failed the restriction.
TooManyException- if more than one element matched the xpath.
query(String)Fetches a single element and wraps it inside a query from the xpath.
public Query query(String xpath) throws NotFoundException, TooManyException;
Fetches a single element and wraps it inside a query from the xpath.
Parameters
xpath- An xpath that is assumed to match only a single , for example: /library
Returns
- Query element.
Throws
NotFoundException- if the expected xpath was not found.
TooManyException- if more than one element matched the xpath.
QueryNetwork
public class QueryNetwork extends Query
Implements network related queries, url:s, hostnames, ip-addresses etc.
QueryNetwork(Object)Build a new query from a DOM node.
public QueryNetwork(Object node);
Build a new query from a DOM node.
Parameters
node- The DOM node from which the paths start when querying.
getInetAddress(String)Retrieve an internet address ipv4 or ipv6.
public static InetAddress getInetAddress(String xpath) throws DecodingException, NotFoundException, TooManyException;
Retrieve an internet address ipv4 or ipv6.
Parameters
xpath- Fetch the value found using this xpath.
Returns
- The iternet address.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getHostname(String)Retrieve a host name, such as mail or gateway or mycomputer.
public static String getHostname(String xpath) throws NotFoundException, DecodingException, TooManyException;
Retrieve a host name, such as mail or gateway or mycomputer.
Parameters
xpath- Use this xpath to find the host name.
Returns
- The hostname.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getFQDN(String)Retrieve a fully qualified domain name, such as mail.mydomain.com.
public static String getFQDN(String xpath) throws NotFoundException, DecodingException, TooManyException;
Retrieve a fully qualified domain name, such as mail.mydomain.com.
Parameters
xpath- Use this xpath to find the host name.
Returns
- The fqdn.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
getURL(String)Retrieve an URL, such as https://foo.bar.com?a=123
public static URL getURL(String xpath) throws NotFoundException, DecodingException, TooManyException;
Retrieve an URL, such as https://foo.bar.com?a=123
Parameters
xpath- Use this xpath to find the host name.
Returns
- The url address.
Throws
NotFoundException- if the expected xpath was not found.
DecodingException- if the value was not an integer or if it failed the restriction.
TooManyException- if more than one element matched the xpath.
QueryScientific
public class QueryScientific extends Query
This class is used to extract scientific values from a DOM.
QueryScientific(Object)Build a new scientific query from a DOM node.
public QueryScientific(Object node);
Build a new scientific query from a DOM node.
Parameters
node- The DOM node from which the paths start when querying.
TooManyException
public class TooManyException extends Exception
The too many exception is thrown when a query expected a single answer but more than one was found.
TooManyException(String)Construct a too many exception.
public TooManyException(String path);
Construct a too many exception.
Parameters
path- The path into the document for which more than one value was found.
XMQColorName
public enum XMQColorName
XMQSyntax: SYNTAX_C: Comments SYNTAX_Q: Standalone quote. SYNTAX_E: Entity SYNTAX_ENS: Element Namespace SYNTAX_EN: Element Name SYNTAX_EK: Element Key SYNTAX_EKV: Element Key Value SYNTAX_ANS: Attribute NameSpace SYNTAX_AK: Attribute Key SYNTAX_AKV: Attribute Key Value SYNTAX_CP: Compound Parentheses SYNTAX_NDC: Namespace declaration SYNTAX_UW: Unicode Whitespace SYNTAX_XSL: The xsl namespace SYNTAX_FG: Foreground text color SYNTAX_BG: Background text color
XMQ_COLOR_CComment
XMQColorName.XMQ_COLOR_C
Comment
XMQ_COLOR_QQuote
XMQColorName.XMQ_COLOR_Q
Quote
XMQ_COLOR_EEntity
XMQColorName.XMQ_COLOR_E
Entity
XMQ_COLOR_NSName Space (both for element and attribute)
XMQColorName.XMQ_COLOR_NS
Name Space (both for element and attribute)
XMQ_COLOR_ENElement Name
XMQColorName.XMQ_COLOR_EN
Element Name
XMQ_COLOR_EKElement Key
XMQColorName.XMQ_COLOR_EK
Element Key
XMQ_COLOR_EKVElement Key Value
XMQColorName.XMQ_COLOR_EKV
Element Key Value
XMQ_COLOR_AKAttribute Key
XMQColorName.XMQ_COLOR_AK
Attribute Key
XMQ_COLOR_AKVAttribute Key Value
XMQColorName.XMQ_COLOR_AKV
Attribute Key Value
XMQ_COLOR_CPCompound Parentheses
XMQColorName.XMQ_COLOR_CP
Compound Parentheses
XMQ_COLOR_NSDName Space Declaration xmlns
XMQColorName.XMQ_COLOR_NSD
Name Space Declaration xmlns
XMQ_COLOR_UWUnicode whitespace
XMQColorName.XMQ_COLOR_UW
Unicode whitespace
XMQ_COLOR_XLSOverride XLS element names with this color.
XMQColorName.XMQ_COLOR_XLS
Override XLS element names with this color.
XMQ_COLOR_FGOverride FG color of text.
XMQColorName.XMQ_COLOR_FG
Override FG color of text.
XMQ_COLOR_BGOverride BG color for terminal.
XMQColorName.XMQ_COLOR_BG
Override BG color for terminal.