Yes, and that is not a given. Many XML-to-object libraries collapse repeated sibling elements into arrays and lose the original ordering, so rebuilding produces a document that is no longer equivalent. This formatter parses in order-preserving mode specifically so the output is a faithful reformat.
Does it validate my XML?
It checks well-formedness — correct nesting, matching tags, legal attribute syntax — and reports the line and column of the first problem. It does not validate against a DTD or XSD schema, which is a separate task requiring the schema document.
Are comments and CDATA kept?
Comments are preserved and re-indented. CDATA sections are kept intact, since their contents are by definition not to be parsed.