File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Adding namespace information to XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Adding namespace information to XML" Watch "Adding namespace information to XML" New topic
Author

Adding namespace information to XML

Sam Prad
Greenhorn

Joined: Mar 12, 2011
Posts: 2
Hi all,

Given an XML document without any namespace information, and its schema, what is the easiest way to add the namespace information in? This is a very general problem, and I think there should be some general solutions out there. Can someone provide pointers on this? Here is a simplified example:

Raw XML:
It is known that the root element PurchaseOrder is of type PurchaseOrderType in namespace "urn:po.api".
These are the sample Schemas:

Based on the above information, the namespace information needs to be added into the Raw XML as follows:
Result XML:

Does anyone have pointers to how this can be done while taking into account all the contructs that XML schema supports?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The software that is creating the XML-based document should create it with the namespace data.
Sam Prad
Greenhorn

Joined: Mar 12, 2011
Posts: 2
Jimmy,

Thanks for yor reply. However that is not an option. The raw XML documents are already without namespace information. The schemas adhere to a restriction such that the raw XML documents will never have two elements with the same local name but in different namespaces as siblings in any part of the XML document. This means that even though there is no namespace information, yet there is no ambiguity for any element.

The first question is this a solvable problem or not?
If not, why not? And if it is solvable, what is the best approach?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Applying namespace data to the known XML instance can be done by an individual with significant XML programming skills. Business requirements for every element and attribute in the instance will be required.

...while taking into account all the contructs that XML schema supports.


Whether this is possible or not depends on the size, complexity, and granularity of the XML language which is defined in the schema AND the programming style of the XML schema itself. If possible, this would require someone with expert-level XML programming skills.

Good luck and welcome to the JavaRanch - A friendly place for programming greehorns!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding namespace information to XML
 
Similar Threads
Schema not works with xjc and java lang reflect Invocation Target Exception error
How to access byte array web method
WSDL issues
error in wsdl
question - "all" group