2

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.