|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object nux.xom.xquery.ResultSequenceSerializer
public class ResultSequenceSerializer
Serializes an XQuery/XPath result sequence onto a given output stream, using
various configurable serialization options such encoding, indentation and
algorithm. The semantics of options are identical to the XOM
Serializer
, except the "algorithm" option.
The W3C algorithm serializes each item in the result sequence according to the XML Output Method of the W3C XQuery/XSLT2 Serialization Spec, with sequence normalization as defined therein. As such, it may output data that is not a well-formed document. For example, if the result sequence contains more than one element then a document with more than one root element will be output. However, for some use cases the algorithm does indeed output a well-formed XML document. For example, if the result sequence contains a single document or element node. Finally, note that an exception is thrown if the result sequence contains a (top-level) attribute node.
In contrast, the wrap algorithm wraps each item in the result sequence into a decorated element wrapper, thereby ensuring that any arbitrary result sequence can always be output as a well-formed XML document. This enables easy processing in subsequent XML processing pipeline stages. Unlike the W3C algorithm, the wrap algorithm does not perform sequence normalization. Thus, wrapping is better suited for XQuery debugging purposes, because one can see exactly what items a query does (or does not) return.
Example usage:
Document doc = new Builder().build(new File("samples/data/p2pio-receive.xml")); Nodes results = XQueryUtil.xquery(doc, "//*"); // Nodes results = XQueryUtil.xquery(doc, "//node(), //@*, 'Hello World!'"); ResultSequenceSerializer ser = new ResultSequenceSerializer(); ser.setEncoding("UTF-8"); ser.setIndent(4); ser.setAlgorithm(ResultSequenceSerializer.W3C_ALGORITHM); // ser.setAlgorithm(ResultSequenceSerializer.WRAP_ALGORITHM); ser.write(results, System.out);
Field Summary | |
---|---|
static String |
W3C_ALGORITHM
Serializes each item in the result sequence according to the XML Output Method of the W3C XQuery/XSLT2 Serialization Draft Spec, with sequence normalization as defined therein. |
static String |
WRAP_ALGORITHM
Serializes each item in the result sequence by wrapping it into a decorated element, without sequence normalization. |
Constructor Summary | |
---|---|
ResultSequenceSerializer()
Constructs and returns a serializer with default options. |
Method Summary | |
---|---|
String |
getAlgorithm()
Returns the current serialization algorithm; Can be W3C_ALGORITHM or WRAP_ALGORITHM ; Defaults to
W3C_ALGORITHM . |
String |
getEncoding()
Returns the current serialization character encoding; Defaults to "UTF-8"; For details, see Serializer.Serializer(OutputStream, String) . |
int |
getIndent()
Returns the number of spaces to insert for each nesting level for pretty printing purposes; Defaults to zero; For details, see Serializer.setIndent(int) . |
boolean |
getUnicodeNormalizationFormC()
Returns whether or not to perform Unicode normalization form C (NFC); Defaults to false; For details, see Serializer.setUnicodeNormalizationFormC(boolean) |
void |
setAlgorithm(String algorithm)
Sets the serialization algorithm. |
void |
setEncoding(String encoding)
Sets the character encoding for the serialization. |
void |
setIndent(int indent)
Sets the number of spaces to insert for each nesting level. |
void |
setUnicodeNormalizationFormC(boolean nfc)
Sets whether or not to perform Unicode normalization form C (NFC). |
String |
toString()
Returns a string representation for debugging purposes. |
void |
write(Nodes nodes,
OutputStream out)
Serializes the given result sequence onto the given output stream. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String W3C_ALGORITHM
public static final String WRAP_ALGORITHM
Constructor Detail |
---|
public ResultSequenceSerializer()
Method Detail |
---|
public String getAlgorithm()
W3C_ALGORITHM
or WRAP_ALGORITHM
; Defaults to
W3C_ALGORITHM
.
public int getIndent()
Serializer.setIndent(int)
.
public String getEncoding()
Serializer.Serializer(OutputStream, String)
.
public boolean getUnicodeNormalizationFormC()
Serializer.setUnicodeNormalizationFormC(boolean)
public void setAlgorithm(String algorithm)
algorithm
- the serialization algorithm to usepublic void setEncoding(String encoding)
encoding
- the encoding to usepublic void setIndent(int indent)
indent
- the indentation to use (must be >= 0)public void setUnicodeNormalizationFormC(boolean nfc)
nfc
- true to normalize with NFC, false otherwise.public String toString()
toString
in class Object
public void write(Nodes nodes, OutputStream out) throws IOException
nodes
- the result sequence to serializeout
- the stream to write to
IOException
- if an I/O error occured
|
Nux 1.6 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |