Class XMQ
java.lang.Object
org.libxmq.XMQ
The XMQ class is used to parse/print/render XMQ/XML/HTML/JSON documents.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddElement(XMQElement parent, String name, NS ns) Add an element as the last child of parent, like xmqAddElement.addElementWithAttrs(XMQElement parent, String name, NS ns, String... attrs) Add an element with attributes, like xmqAddElementWithAttrs.addKeyValue(XMQElement parent, String key, String value, NS ns) Add an element with a text value, key=value in xmq, like xmqAddKeyValue.addKeyValueWithAttrs(XMQElement parent, String key, String value, NS ns, String... attrs) Add an element with a text value and attributes, like xmqAddKeyValueWithAttrs.voidaddNamespace(XMQElement element, NS ns) Declare a namespace with a prefix on an element, without using it for the element itself, like xmqAddNamespace.addRootElement(XMQDoc doc, String name, NS ns) Add the root element to the document, like xmqAddRootElement.compactQuote(String content) Quote a value as xmq on a single line, eg 'car go' or ('howdy' 'dowdy'), like xmqCompactQuote.compileIXML(String grammar) Compile an ixml grammar, to parse inputs with parseBufferWithIXML.newDoc()Create a new empty document, like xmqNewDoc.static XMQDocCreate a document from an xmq buffer, like xmqOf in C: a newDoc and a parseBuffer in one call.parseBuffer(String buffer, InputSettings is) Parse a buffer containing XMQ/XML/HTML/JSON/CLINES.parseBufferWithIXML(byte[] buffer, IXML ixml) Parse an UTF-8 buffer with an ixml grammar, like xmqParseBufferWithIXML.parseBufferWithIXML(String buffer, IXML ixml) Parse a buffer with an ixml grammar, like xmqParseBufferWithIXML.parseFile(Path file, InputSettings is) Parse a file containing XMQ/XML/HTML/JSON/CLINES.static StringRender a locale adapted text cli error printout of a parse exception using the default locale.static StringprintException(ParseException e, Locale locale) Render a locale adapted text cli error printout of a parse exception.queryBuffer(String buffer, InputSettings is) Parse a buffer containing XMQ/XML/HTML/JSON/CLINES and return a Query object for the DOM.queryFile(Path file, InputSettings is) Parse a file containing XMQ/XML/HTML/JSON/CLINES and return a Query object to the DOM.renderHTML(XMQDoc doc, OutputSettings os) Render the document as XMQ in HTML.renderTEX(XMQDoc doc, OutputSettings os) Render the document as XMQ in TeX.voidsetDocType(XMQDoc doc, String name) Set the doctype of the document, eg html, like xmqSetDocType.toCLINES(XMQDoc doc, OutputSettings os) Print the document as clines.toHTML(XMQDoc doc, OutputSettings os) Print the document as HTML.toJSON(XMQDoc doc, OutputSettings os) Print the document as json.toXML(XMQNode doc, OutputSettings os) Print the document as XML.toXMQ(XMQNode doc, OutputSettings os) Print the document as XMQ.
-
Constructor Details
-
XMQ
public XMQ()Construct an XMQ using the xmq DOM implementation.
-
-
Method Details
-
parseFile
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
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
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
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
-
of
Create a document from an xmq buffer, like xmqOf in C: a newDoc and a parseBuffer in one call.- Parameters:
s- The xmq to parse.- Returns:
- The document.
- Throws:
ParseException- if the buffer cannot be parsed as xmq.
-
setDocType
-
addRootElement
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
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
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
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
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
public XMQElement addKeyValueWithAttrs(XMQElement 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
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
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
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
-
toXMQ
Print the document as XMQ.- Parameters:
doc- Document to print.os- Settings for printing.- Returns:
- A string with XMQ.
-
toXML
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
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 )- Parameters:
doc- Document to print.os- Settings for printing.- Returns:
- A string with HTML.
-
toJSON
Print the document as json.- Parameters:
doc- Document to print.os- Settings for printing.- Returns:
- A string with JSON.
-
toCLINES
Print the document as clines.- Parameters:
doc- Document to print.os- Settings for printing.- Returns:
- A string with clines.
-
renderHTML
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 renderos- Settings for rendering- Returns:
- A string with HTML.
-
renderTEX
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 renderos- Settings for rendering- Returns:
- A string with TeX commands.
-
printException
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
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.
-