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 two XSDs and namespace problem. 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 "two XSDs and namespace problem." Watch "two XSDs and namespace problem." New topic
Author

two XSDs and namespace problem.

kasun chathuranga
Greenhorn

Joined: Apr 27, 2006
Posts: 22
Hi Friends,
I got a problem in JAXB. I'm using JAXB 2.1.7, jBoss 5.1.0, maven 1.x, eclipse indigo.

I have two xsd files. let's say A.xsd and B.xsd. A.xsd is a common file, so have to place it in different module(com.aaa), and generated classes are also located separately.
A.xsd is importing (or incliding - you may suggest) into the B.xsd file which is inside a separate module (com.bbb). When we compiling B.xsd file, generated classes should goes to com.bbb, and should only contain B.xsd related classes only (not A.xsd related classes) I have mention com.aaa as a episode in POM file.

In this case A.xsd and B.xsd should (I think) under different namespaces, otherwise A.xsd related classes also generated in the same location where B.xsd related classes are.

Since the situation as this, in my data xml file should not contain only one namespace (<personlist xmlns="bbb.com"). Simply I can add another namespace to the xml file and mention necessary prefixes in related elements.

But unfortunately xml file should be as same, and my A.xsd and B.xsd structure also should keep as discuss above.

I know this is crazy, but is there any option which can be try...

Thankx in advance...!!!

Chathuranga.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
It sounds like you should stop using JAXB and the XML Schemas for a while at least.

If you need to read XML and create Java data objects, then use Simple API for XML and implement your own Java-based binding component (Much easier than it sounds.)

1. Validate XML with Schemas
2. Bind to Java data objects (with your own code, no JAXB or XML Beans or XML Schemas)
3. Process data


If you need to create an XML-based file from Java data objects, then simply create a series of toXML() methods in the data objects (Also much easier than using XML Schemas and JAXB.)

1. Create XML file (with your own code, no XML Schemas or JAXB or XML Beans)
2. Validate XML file with Schemas

In both scenarios above you still are using the Schemas to validate the XML document, your simply not using them to execute complex data processing. The XML Schema language is non-object-oriented and overly complex. It is best to keep it for validation only and leave data processing and manipulation to Java code only. When you attempt to mix them, you end up with ********

kasun chathuranga
Greenhorn

Joined: Apr 27, 2006
Posts: 22
Hi Jimmy,
Yes. Thats sounds good. Because If I depend someone else code, have to play within their frame. Better to write my own component for that.

BTW any idea about JiBX..? It says JiBX is more flexible than JAXB. Will it fit to that scenario I expected?

Thankx for the idea..!!!

Best Regards,
Chathuranga.

Jimmy Clark wrote:It sounds like you should stop using JAXB and the XML Schemas for a while at least.

If you need to read XML and create Java data objects, then use Simple API for XML and implement your own Java-based binding component (Much easier than it sounds.)

1. Validate XML with Schemas
2. Bind to Java data objects (with your own code, no JAXB or XML Beans or XML Schemas)
3. Process data


If you need to create an XML-based file from Java data objects, then simply create a series of toXML() methods in the data objects (Also much easier than using XML Schemas and JAXB.)

1. Create XML file (with your own code, no XML Schemas or JAXB or XML Beans)
2. Validate XML file with Schemas

In both scenarios above you still are using the Schemas to validate the XML document, your simply not using them to execute complex data processing. The XML Schema language is non-object-oriented and overly complex. It is best to keep it for validation only and leave data processing and manipulation to Java code only. When you attempt to mix them, you end up with ********

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
As I suggested, it is best to keep a clean separation between the XML Schema language and complex object-oriented data processing and manipulation. XML Schemas and XML DTDs are good tools for validation of XML-based documents and for creating XML-based markup languages. That is about it.

When you need to create XML-based documents or read from XML-based documents for data processing, you do not need to use an XML Schema or object-oriented versions of XML Schema constructs to do it.

The XML Schema language is non-object-oriented and overly complex. It is best to keep it for validation only and leave data processing and manipulation to Java code only. When you attempt to mix them, you end up with ********

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: two XSDs and namespace problem.