Package com.topologi.diffx
Class Extension
java.lang.Object
com.topologi.diffx.Extension
To use Diff-X as an XSLT extension.
In Saxon, declare the namespace as:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:diffx="com.topologi.diffx.Extension"
extension-element-prefixes="diffx"
>
Diff-X can be called within XSLT with:
<xsl:copy-of select="diffx:diff(/node1/to/compare, /node2/to/compare, 'IGNORE', 'TEXT')"/>
Note: the method signatures requires DOM arguments, include the Saxon-DOM jar
on your classpath to use this extension function with Saxon.- Version:
- 18 May 2010
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voiddiff(EventSequence seq1, EventSequence seq2, Writer out, DiffXConfig config) Compares the two specified xml files and prints the diff onto the given writer.static NodeCompares the two specifiedNodes and returns the diff as a node.private static StringgetFactoryClass(Node xml1, Node xml2) Returns the factory class to use based on the givenNodeLists.private static DiffXConfigReturns the Diff-X config for the specified argument as String.private static NodetoNode(String xml, DiffXConfig config, String factory) Returns a node for the specified string value.
-
Field Details
-
BUILDERS
Maps the DOM builder factory to use with the given DOM package.This is because some XSLT processors will only accept certain types DOM objects.
-
-
Constructor Details
-
Extension
public Extension()
-
-
Method Details
-
diff
public static Node diff(Node xml1, Node xml2, String whitespace, String granularity) throws DiffXException, IOException Compares the two specifiedNodes and returns the diff as a node.Only the first node in the node list is sequenced.
- Parameters:
xml1- The first XML node to compare.xml2- The second XML node to compare.whitespace- The white space processing (a validWhiteSpaceProcessingvalue).granularity- The text granularity (a validTextGranularityvalue).- Throws:
DiffXException- Should a Diff-X exception occur.IOException- Should an I/O exception occur.
-
diff
private static void diff(EventSequence seq1, EventSequence seq2, Writer out, DiffXConfig config) throws DiffXException, IOException Compares the two specified xml files and prints the diff onto the given writer.- Parameters:
seq1- The first XML reader to compare.seq2- The first XML reader to compare.out- Where the output goes.config- The DiffX configuration to use.- Throws:
DiffXException- Should a Diff-X exception occur.IOException- Should an I/O exception occur.
-
toConfig
Returns the Diff-X config for the specified argument as String.- Parameters:
whitespace- A valid white space processing value.granularity- A valid text granularity value.- Returns:
- the Diff-X config for the specified arguments as String.
-
toNode
private static Node toNode(String xml, DiffXConfig config, String factory) throws IOException, ParserConfigurationException, SAXException Returns a node for the specified string value.- Parameters:
xml- The XML to parse.config- The DiffX configuration to use.factory- The class name of the DOM builder factory.- Returns:
- the corresponding document node.
- Throws:
IOExceptionParserConfigurationExceptionSAXException
-
getFactoryClass
Returns the factory class to use based on the givenNodeLists.- Parameters:
xml1- the first node list.xml2- the second node list.
-