This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark ""force" a namespace?" Watch ""force" a namespace?" New topic
Author

"force" a namespace?

Ed Ip
Greenhorn

Joined: Mar 28, 2005
Posts: 3
Hi all,

I am writing a CFX (Cold Fusion extension) that will parse and validate an XML against a predefined XSD using JAXP. It is working fine, except there is one functionality that I need some help with...

If a namespace is declared in an XML, and not so in the XSD, I found to be able to ignore that difference via DocumentBuilderFactory .setNamespaceAware(false). But, in reverse, if a namespace is declared in the XSD, but not so in the XML, I would get an error stating some error to the extend of not being able to locate the first node.

My question is, is there a way to "force" a namespace so the parser would think a namespace exists in the XML?

Since I am somewhat new to the java and XML world, if my question doesn't seem clear, please let me know.

Thx in advance.

Ed
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Welcome to Javaranch, Ed.

Well this is a classic age old problem. The link between XMl Schema validation, XML Namespace and the XML tags.

You can learn all about this "feature" here.
Sorry about the redirect here but I don't want to say something that will confuse you even more. If I could suggest, give that a reading and lets discuss any more doubts you may have.

Thanks.

- m


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Ed Ip
Greenhorn

Joined: Mar 28, 2005
Posts: 3
Hi Madhav,

Thanks for the welcome and the URL. It was very informative.

We're having approx. 500 providers that will be submitting XMLs into our system. Unfortunately, a majority of them are not all that technically savvey, so I am beginning to see issues with XML having left out the xmlns declaration.

So, not to bore you with my problems, but I guess my question still stand....is there a way to dynamically force a default namespace while using a ns-aware parser? Meaning, at time of validation, if the parser does not see a default xmlns, go ahead and use whatever we declare as the default programmatically.

Thx in advance.

Ed
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Originally posted by Ed Ip:
Hi Madhav,

So, not to bore you with my problems,
No, technical problems never bore me, just the management stuff.....

but I guess my question still stand....is there a way to dynamically force a default namespace while using a ns-aware parser? Meaning, at time of validation, if the parser does not see a default xmlns, go ahead and use whatever we declare as the default programmatically.


Well, that would depend on what you mean by programatically declared default.

For example this is a pesudo-code scenario I can imagine happening:

You run each of your (500 or so) XML's through a validator.
If (validation fails)
then run the input XML file through a Style Sheet (or if you are using DOM) add the default namespace programatically
(endif)
Run the XML file through your business logic.

Is this something that you are thinking of?

That could be a possibility but you are creating a partial 'solution' and not solving the original problem.
Hopefully others may pitch in their thoughts as well.

Thanks.

- m
[ April 05, 2005: Message edited by: Madhav Lakkapragada ]
Ed Ip
Greenhorn

Joined: Mar 28, 2005
Posts: 3
Hi Madhav,

That is exactly what I am thinking. But, I also agree that IS just a partial solution. I think until I understand how to "rewrite" the XML, I simply going to ask all the providers to include the xmlns declaration.

Thx.

Ed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "force" a namespace?