wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Facing problem with JAXB1.0 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 "Facing problem with JAXB1.0" Watch "Facing problem with JAXB1.0" New topic
Author

Facing problem with JAXB1.0

yogesh chaudhari
Greenhorn

Joined: Dec 16, 2008
Posts: 3
Hi All,

In our project we are using JAXB1.0. I have a DOM object. and I want to set the value of an attribute. After setting attribute value, when I print DOM object it correctly shows that attribute. But on client side after unmarshalling it returns the attribute value as null.

XSD uses namespace & same namespace URL is showing in XML document.

schema detail is as below..

<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.abcd.com/AtASchema" targetNamespace="http://www.abcd.com/AtASchema" elementFormDefault="qualified" version="1.0">
.......

and corresponding xml in DOM is...

<?xml version="1.0" encoding="UTF-8"?>
<PartnerPartyProfile AttributeStatus="Cached" xmlns="http://www.abcd.com/AtASchema"><PartnerBeGeo>......
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Did you create the attribute in your DOM with no namespace, or with the default namespace? I'm sure DOM will allow you to do the latter, but you shouldn't because unprefixed attributes are always in no namespace and not in the default namespace.
yogesh chaudhari
Greenhorn

Joined: Dec 16, 2008
Posts: 3
Thanks for the reply. we are creating attribute in DOM object the code is as below

NodeList childNodes=docResult.getChildNodes();

Element profileElement=(Element)childNodes.item(0);

//profileElement.setAttribute("AttributeStatus", status);

profileElement.setAttributeNS("http://www.abcd.com/AtASchema","AttributeStatus", status);
profileElement.setPrefix("");
............................................................
when I used setAttributeNS method and mention namespace in that it gives the desired output but 'ns1' as a prefix for every element. XML output after unmarshalling for the same is as below

<ns1:CommerceProfile ns1:AttributeStatus='Cached' xmlns:ns1='http://www.abcd.com/AtASchema'>
<ns1:AccessAndApproval>
<ns1:IPCAccess>
12
</ns1:IPCAccess>..... ...

Why its displaying prefix ns1 .
The desired output XML should be like this..

<CommerceProfile AttributeStatus='Cached' >
<AccessAndApproval>
<IPCAccess>
12
</IPCAccess>
yogesh chaudhari
Greenhorn

Joined: Dec 16, 2008
Posts: 3
Sorry, I missed something in desired XML output. The desired output is as below

<CommerceProfile AttributeStatus='Cached' xmlns="http://www.abcd.com/AtASchema">
<AccessAndApproval>
<IPCAccess>
12
</IPCAccess>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Facing problem with JAXB1.0