org.jibx.extras
Class DocumentComparator

java.lang.Object
  extended byorg.jibx.extras.DocumentComparator

public class DocumentComparator
extends java.lang.Object

XML document comparator. This uses XMLPull parsers to read a pair of documents in parallel, comparing the streams of components seen from the two documents. The comparison ignores differences in whitespace separating elements, but treats whitespace as significant within elements with only character data content.

Author:
Dennis M. Sosnoski

Field Summary
protected  java.io.PrintStream m_differencePrint
          Print stream for reporting differences.
protected  org.xmlpull.v1.XmlPullParser m_parserA
          Parser for first document.
protected  org.xmlpull.v1.XmlPullParser m_parserB
          Parser for second document.
 
Constructor Summary
DocumentComparator(java.io.PrintStream print)
          Constructor.
 
Method Summary
protected  java.lang.String buildName(java.lang.String ns, java.lang.String name)
          Build name string.
protected  java.lang.String buildPositionString(org.xmlpull.v1.XmlPullParser parser)
          Build parse input position description.
 boolean compare(java.io.Reader rdra, java.io.Reader rdrb)
          Compares a pair of documents by reading them in parallel from a pair of parsers.
protected  boolean matchAttributes()
          Verifies that the attributes on the current start tags match.
protected  boolean matchNames()
          Verifies that the current start or end tag names match.
protected  boolean matchText(java.lang.String texta, java.lang.String textb, java.lang.String lead)
          Check if two text strings match, ignoring leading and trailing spaces.
protected  void printError(java.lang.String msg)
          Prints error description text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_parserA

protected org.xmlpull.v1.XmlPullParser m_parserA
Parser for first document.


m_parserB

protected org.xmlpull.v1.XmlPullParser m_parserB
Parser for second document.


m_differencePrint

protected java.io.PrintStream m_differencePrint
Print stream for reporting differences.

Constructor Detail

DocumentComparator

public DocumentComparator(java.io.PrintStream print)
                   throws org.xmlpull.v1.XmlPullParserException
Constructor. Builds the actual parser.

Parameters:
print - print stream for reporting differences
Throws:
org.xmlpull.v1.XmlPullParserException - on error creating parsers
Method Detail

buildPositionString

protected java.lang.String buildPositionString(org.xmlpull.v1.XmlPullParser parser)
Build parse input position description.

Parameters:
parser - for which to build description
Returns:
text description of current parse position

buildName

protected java.lang.String buildName(java.lang.String ns,
                                     java.lang.String name)
Build name string.

Parameters:
ns - namespace URI
name - local name
Returns:
printable names string

printError

protected void printError(java.lang.String msg)
Prints error description text. The generated text include position information from both documents.

Parameters:
msg - error message text

matchAttributes

protected boolean matchAttributes()
Verifies that the attributes on the current start tags match. Any mismatches are printed immediately.

Returns:
true if the attributes match, false if not

matchText

protected boolean matchText(java.lang.String texta,
                            java.lang.String textb,
                            java.lang.String lead)
Check if two text strings match, ignoring leading and trailing spaces. Any mismatch is printed immediately, with the supplied lead text.

Parameters:
texta -
textb -
lead - error text lead
Returns:
true if the texts match, false if not

matchNames

protected boolean matchNames()
Verifies that the current start or end tag names match.

Returns:
true if the names match, false if not

compare

public boolean compare(java.io.Reader rdra,
                       java.io.Reader rdrb)
Compares a pair of documents by reading them in parallel from a pair of parsers. The comparison ignores differences in whitespace separating elements, but treats whitespace as significant within elements with only character data content.

Parameters:
rdra - reader for first document to be compared
rdrb - reader for second document to be compared
Returns:
true if the documents are the same, false if they're different


Project Web Site