Class Canonicalizer
- java.lang.Object
-
- nu.xom.canonical.Canonicalizer
-
public class Canonicalizer extends java.lang.ObjectWrites XML in the format specified by Canonical XML Version 1.0 or Exclusive XML Canonicalization Version 1.0. Canonical XML 1.1 support is in progress.
- Version:
- 1.3.1
- Author:
- Elliotte Rusty Harold
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCANONICAL_XMLstatic java.lang.StringCANONICAL_XML_11static java.lang.StringCANONICAL_XML_11_WITH_COMMENTSstatic java.lang.StringCANONICAL_XML_WITH_COMMENTSstatic java.lang.StringEXCLUSIVE_XML_CANONICALIZATIONstatic java.lang.StringEXCLUSIVE_XML_CANONICALIZATION_WITH_COMMENTS
-
Constructor Summary
Constructors Constructor Description Canonicalizer(java.io.OutputStream out)Creates aCanonicalizerthat outputs a canonical XML document with comments.Canonicalizer(java.io.OutputStream out, boolean withComments)Creates aCanonicalizerthat outputs a canonical XML document with or without comments.Canonicalizer(java.io.OutputStream out, java.lang.String algorithm)Creates aCanonicalizerthat outputs a canonical XML document using the specified algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetInclusiveNamespacePrefixList(java.lang.String inclusiveNamespacePrefixes)Specifies the prefixes that will be output as specified in regular canonical XML, even when doing exclusive XML canonicalization.voidwrite(Node node)Serializes a node onto the output stream using the specified canonicalization algorithm.voidwrite(Nodes documentSubset)Serializes a document subset onto the output stream using the canonical XML algorithm.
-
-
-
Field Detail
-
CANONICAL_XML
public static final java.lang.String CANONICAL_XML
- See Also:
- Constant Field Values
-
CANONICAL_XML_WITH_COMMENTS
public static final java.lang.String CANONICAL_XML_WITH_COMMENTS
- See Also:
- Constant Field Values
-
EXCLUSIVE_XML_CANONICALIZATION
public static final java.lang.String EXCLUSIVE_XML_CANONICALIZATION
- See Also:
- Constant Field Values
-
EXCLUSIVE_XML_CANONICALIZATION_WITH_COMMENTS
public static final java.lang.String EXCLUSIVE_XML_CANONICALIZATION_WITH_COMMENTS
- See Also:
- Constant Field Values
-
CANONICAL_XML_11
public static final java.lang.String CANONICAL_XML_11
- See Also:
- Constant Field Values
-
CANONICAL_XML_11_WITH_COMMENTS
public static final java.lang.String CANONICAL_XML_11_WITH_COMMENTS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Canonicalizer
public Canonicalizer(java.io.OutputStream out)
Creates a
Canonicalizerthat outputs a canonical XML document with comments.- Parameters:
out- the output stream the document is written onto
-
Canonicalizer
public Canonicalizer(java.io.OutputStream out, boolean withComments)Creates a
Canonicalizerthat outputs a canonical XML document with or without comments.- Parameters:
out- the output stream the document is written ontowithComments- true if comments should be included in the output, false otherwise
-
Canonicalizer
public Canonicalizer(java.io.OutputStream out, java.lang.String algorithm)Creates a
Canonicalizerthat outputs a canonical XML document using the specified algorithm. Currently, four algorithms are defined and supported:- Canonical XML without comments:
http://www.w3.org/TR/2001/REC-xml-c14n-20010315 - Canonical XML with comments:
http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments - Exclusive XML canonicalization without comments:
http://www.w3.org/2001/10/xml-exc-c14n# - Exclusive XML canonicalization with comments:
http://www.w3.org/2001/10/xml-exc-c14n#WithComments
- Parameters:
out- the output stream the document is written ontoalgorithm- the URI for the canonicalization algorithm- Throws:
CanonicalizationException- if the algorithm is not recognizedjava.lang.NullPointerException- if the algorithm is null
- Canonical XML without comments:
-
-
Method Detail
-
write
public final void write(Node node) throws java.io.IOException
Serializes a node onto the output stream using the specified canonicalization algorithm. If the node is a document or an element, then the node's entire subtree is written out.
- Parameters:
node- the node to canonicalize- Throws:
java.io.IOException- if the underlyingOutputStreamencounters an I/O error
-
write
public final void write(Nodes documentSubset) throws java.io.IOException
Serializes a document subset onto the output stream using the canonical XML algorithm. All nodes in the list must come from same document. Furthermore, they must come from a document. They cannot be detached. The nodes need not be sorted. This method will sort them into the appropriate order for canonicalization.
In most common use cases, these nodes will be the result of evaluating an XPath expression. For example,
Canonicalizer canonicalizer = new Canonicalizer(System.out, Canonicalizer.CANONICAL_XML); Nodes result = doc.query("//. | //@* | //namespace::*"); canonicalizer.write(result);Children are not output unless the subset also includes them. Including an element in the subset does not automatically select all the element's children, attributes, and namespaces. Furthermore, not selecting an element does not imply that its children, namespaces, attributes will not be output.
- Parameters:
documentSubset- the nodes to serialize- Throws:
java.io.IOException- if the underlyingOutputStreamencounters an I/O errorCanonicalizationException- if the nodes come from more than one document; or if a detached node is in the list
-
setInclusiveNamespacePrefixList
public final void setInclusiveNamespacePrefixList(java.lang.String inclusiveNamespacePrefixes)
Specifies the prefixes that will be output as specified in regular canonical XML, even when doing exclusive XML canonicalization.
- Parameters:
inclusiveNamespacePrefixes- a whitespace separated list of namespace prefixes that will always be included in the output, even in exclusive canonicalization
-
-