Meaningless Drivel is fun!*
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Facing problem with JAXB1.0" Watch "Facing problem with JAXB1.0" New topic

Facing problem with JAXB1.0

yogesh chaudhari

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="" xmlns:tns="" targetNamespace="" elementFormDefault="qualified" version="1.0">

and corresponding xml in DOM is...

<?xml version="1.0" encoding="UTF-8"?>
<PartnerPartyProfile AttributeStatus="Cached" xmlns=""><PartnerBeGeo>......
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

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

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("","AttributeStatus", status);
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=''>
</ns1:IPCAccess>..... ...

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

<CommerceProfile AttributeStatus='Cached' >
yogesh chaudhari

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

<CommerceProfile AttributeStatus='Cached' xmlns="">
I agree. Here's the link:
subject: Facing problem with JAXB1.0
Similar Threads
update an XML doc
Validating XML against Schema.
problem in importing multiple schema in same namespace
XML Schema: Use of Import
XSD Schema Error in WSAD