views:

188

answers:

1

I can validate an xml with schema in java using DOM parser. But here both the schema and xml file have namespace.

Now I want to validate an xml without namespace with schema. How to achieve this

Thanks Bapi

+1  A: 

Basically, your document does not match schema, so it is not supposed to work. Ideally, you would fix xml document to have proper namespace; or schema to validate non-namespace structure.

But assuming that does not work, you could pre-process XML content in question and change elements/attributes to be in expected namespace(s). This can be done using DOM, SAX or Stax processing. Since DOM is usually built from a SAX source, it might be simplest to just have a simple chaining SAX content handler that "adds" namespace for elements, attributes: this is done by receiving callback, modifying argument(s) before calling chained handler. I'm pretty sure you can google for example code, this is a fairly common use case; esp. since many developers just do not take their time to understand how XML namespaces work. Namespaces are not rocket science, but it is still possible to misunderstand role of prefixes vs namespace URIs.

Hope this helps.

StaxMan