This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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 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.
Joined: Jun 03, 2000
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.
- m [ April 05, 2005: Message edited by: Madhav Lakkapragada ]
Joined: Mar 28, 2005
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.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com