xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
Re: [XOM-interest] Serialize parentless Text nodes
- From: Wolfgang Hoschek <whoschek AT lbl.gov>
- To: Elliotte Harold <elharo AT metalab.unc.edu>
- Cc: xom-interest AT lists.ibiblio.org
- Subject: Re: [XOM-interest] Serialize parentless Text nodes
- Date: Fri, 8 Jul 2005 12:19:20 -0700
On Jul 8, 2005, at 12:03 PM, Elliotte Harold wrote:
Wolfgang Hoschek wrote:
Can we please allow parentless Text nodes in Serializer?
Is it just parentless text nodes you need, or do you also need parentless comments, PIs, and everything else for XQuery serialization? Or is it that those things can already be parentless, and Serializer only imposes an implicit parented constraint on Text?
For the W3C XQuery Serialization spec, all result sequence nodes to be serialized may be parentless, except attributes and namespaces. Should be easy to fix as far as I can see...
[Don't ask me for the questionable rationale behind that spec. I'm also implementing an alternative wrapped algorithm]
/**
* 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
* {@link Serializer}, except the "algorithm" option.
* <p>
* The <b>W3C algorithm</b> 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.
* <p>
* In contrast, the <b>wrap algorithm</b> 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 performs, 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.
* <p>
* Example usage:
* <pre>
* 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);
* </pre>
*
* @author whoschek.AT.lbl.DOT.gov
* @author $Author: hoschek3 $
* @version $Revision: 1.24 $, $Date: 2005/07/07 00:49:08 $
*/
public class ResultSequenceSerializer {
-
Re: [XOM-interest] Serialize parentless Text nodes,
Elliotte Harold, 07/08/2005
-
Re: [XOM-interest] Serialize parentless Text nodes,
Wolfgang Hoschek, 07/08/2005
- Re: [XOM-interest] Serialize parentless Text nodes, Michael Kay, 07/09/2005
- <Possible follow-up(s)>
-
Re: [XOM-interest] Serialize parentless Text nodes,
Wolfgang Hoschek, 07/09/2005
- Re: [XOM-interest] Serialize parentless Text nodes, Michael Kay, 07/10/2005
-
Re: [XOM-interest] Serialize parentless Text nodes,
Elliotte Harold, 07/24/2005
- Re: [XOM-interest] Serialize parentless Text nodes, Wolfgang Hoschek, 07/25/2005
-
Re: [XOM-interest] Serialize parentless Text nodes,
Wolfgang Hoschek, 07/08/2005
Archive powered by MHonArc 2.6.24.