Wednesday, December 17, 2008

Java XML validation, "Cannot find the declaration of element"?

Many thanks to Santiago Pericas-Geertsen, who blogged about this exact problem earlier this year. If you can't figure out for the life of you why your document won't validate, even though you know it's valid, try setting setNamespaceAware(true) on your DocumentBuilderFactory:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);

Chances are that's all you need and you'll be up and running.

Programming is easy, it's all the gotchas that make it hard.

2 comments:

light fiber said...

Thanks a lot! Saved me a lot of headache

mase said...

Great! Your post about this "cannot find the declaration of element" error saved me probably hours of searching in google!