views:

115

answers:

1

Anyone know an app/service/method that I could use to validate a bunch of XML files for UTF-8?

Basically I have a ton of XML files that are suppose to be UTF-8 and some of them happen to contain some bogus characters causing them not to render right in the content viewer.

I know I can check one at a time with methods found in this answer: http://stackoverflow.com/questions/115210/utf-8-validation

...but how about thousands of XML files at once?

A: 

Why can't you take one of the solutions from the linked question and apply them to your situation? It seems like it'd be fairly simple to iterate over all the files you want to check, run iconv -f utf8 on them and emit a list of files where that fails.

Update
Since you haven't specified the situation or environment under which you need to do this test, it's hard to offer concrete advice. The post you linked offers methods of testing what you want, so it's just a matter of knowing what you have available to implement a solution.

Assuming a basic *nix envornment, this simple shell script provides a basic check, caveat the typical filename globbing issues.

#!/bin/sh
for f in *.xml; do
    if ! iconv -f utf8 $f >/dev/null 2>&1; then
        echo $f
    fi
done

Unless you provide more information about your specific requirements though, it's difficult to know whether any answers people have is actually relevant.

jamessan
I guess that is the point of this question, I don't know how to do that..
shogun