Skip to main content

setting default namespace programmatically

3 replies [Last post]
slde
Offline
Joined: 2008-03-26
Points: 0

Hi,

I got an xml-document which I validate against a schema document by JAXP/DOM. I set the schema location via Attribute "http://java.sun.com/xml/jaxp/properties/schemaSource". My Schema got a targetNamespace (mynamespace), so my xml instance document needs a default-Namespace. Is there a chance to specify the default-Namespace programmatically, so that I can remove it from the xml instance dataset?

Example:
XML-File:
<?xml version="1.0" encoding="UTF-8"?>

TIA
sl

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

I don't think you could set the default namespace programmatically. I'm curious, why would you need to remove the default NS from the xml instance?

Joe

slde
Offline
Joined: 2008-03-26
Points: 0

Hi Joe,

the xml instance document is created externally without the default namespace attribute. But the schema-file defines a target namespace. So validating the xml-file brings up an error. I was looking for a solution, where we don't have to change the creation of the xml document.

sl

joehw
Offline
Joined: 2004-12-15
Points: 0

I see. So you really don't have control over the xml instance. By using a validating DOM parser, you would be doing paring and validating in one step in which case you would not be able to set the default namespace programmatically.

What you could do is to separate the parsing and validating into two steps using the Validation API, in which case you would have a chance adding the default namespace after the document is loaded. You could then send to document to a validator for validation.

Joe