Skip to main content

A Little Fuzzy about JAXB and Namespaces

2 replies [Last post]
Joined: 2006-11-23

Hello Everyone,

I will be the first to admit I don't know very much concerning JAXB. This is my first project I am using JAXB. If my questions are trivial, please excuse my "innocence."

What I have done is create several Domain Objects for use in a Web Service. I have created schemas for the domain objects. I have the web service working and the XML response is being built correctly in nearing every case. I am using annotations to document my JAXB Mapping. However, I have two problems.

1. The ordering of the elements as described in the schema is not correct.
2. The namesspaces and prefixes are not working as I would expect them.

Here is what I have in the XML created by JAXB.


Heres is how I have it declared in the Domain objects:

<br />
@XmlRootElement(name="Record",<br />
        namespace="http://localhost/my_metadata_db/schema/myInfo")<br />
public class MyDocument {<br />

What I would suspect is I have not fully annotated the class correctly because this is how the elements look in the XML for the above declaration:

<p>         A<br />
         Great Expectations<br />
         12345<br />
         98213-123978<br />
         BigGuy.pfd<br />
         12345<br />
         123456<br />
         2008-06-24T19:36:06.513-05:00<br />
         2008-06-24T19:36:06.513-05:00<br />

I would suspect the prefix in this case for the above elements would be "ns5" but it is not. The correct order for any populated element should be:

1. ID
2. Path
3. Name
4. DistStmt
5. NSN
6. DocNo
7. Size
8. RevDate
9. Date
10. PageCnt
11. CRC
12. Hash
13. Platform
14. Type
15. Priority

Can someone be so kind and point me to some documentation that would help be get the namespaces correctly and how I might order these elements?

Thanks for taking the time to read my post and for any suggestions you may offer!


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-11-23

Okay, I've figured out the ordering of elements issue.....

@XmlType(name="", propOrder={"myDocumentId", "path", "fileName", "distStatment", "documentNSN",
"documentNumber", "fileSize", "lastUpdated", "documentDesc", "osDate",
"pageCount", "crc", "hash", "platform", "type", "priority"})


I was not adding the name attribute to the @XmlType annotation.


Joined: 2006-11-23

okay I figured it out. Instead of declaring the namespace at the class level, I have to declare the namespace at each element in the class.

I am still a little fuzzy with the correct ordering of the elements.