Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4036048
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:10:30+00:00 2026-05-20T12:10:30+00:00

I am currently trying to use the XMLUnit library to compare two XML files.

  • 0

I am currently trying to use the XMLUnit library to compare two XML files.
One of them, the candidate, is generated by my code from Java Objects (using JAXB) and the other one is the reference (I cannot modify it).
Basically I am trying to prove that given a reference XML file I can unserialize it (using Jaxb and some classes of my own) then serialize it back to another file and still have the same content.

The library seems to furnish the services I need but when the generated file is not properly indented (in kind of a “pretty-print” version) the comparison fails and it doesn’t when indentation is OK.
For example when the candidate is generated there is no indentation, the content is a one-liner, if a indent it properly (manually) the comparison is OK.

Here is the error message generated by XMLUnit:

[different] Expected number of child
nodes ‘3’ but was ‘1’

Do you guys have any idea to solve this?
Maybe the solution is to generate a pretty-print version of the candidate, in this case do you have an idea to combine it with the JAXB serialiser?

By the way if you now a better solution in Java to compare XML files I’ll be glad to know it 😉

Thanks in advance for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:10:30+00:00Added an answer on May 20, 2026 at 12:10 pm

    You can relax some of the constraints used by XMLUnit when comparing to trees by setting properties on the org.custommonkey.xmlunit.XMLUnit class.

    In your case, you probably want:

    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreWhitespace(true);
    XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
    

    You may also find the setIgnoredAttributeOrder property helpful as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to use the android library android fu to help me
I am currently trying to use NAnt and CruiseControl.NET to manage various aspects of
I currently use VS 2008 Professional, but I'm trying to get Team System Developer
I'm currently trying to read in an XML file, make some minor changes (alter
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console
I'm currently trying to use a certain SDK that has me loading functions off
I'm currently trying to use the YouTube API as part of a jQuery plugin
I am currently trying to use the CloudDrive (Powershell) sample that comes with the
I am currently trying to use a web service I developed within an Integration
I'm currently trying to use regular expressions in C#: Regex reg_gameinfo = new Regex(@PokerStars

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.