<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff
size=2>Martin,</FONT></SPAN></DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff size=2>I
believe the FAQ on the JDOM site has some info regarding
namespaces.</FONT></SPAN></DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff size=2>If you
remove the namespace from a 'parent' element then any child elements will have
the xmlns="" representation when output.</FONT></SPAN></DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff size=2>If the
entire document is in a single namespace then you might want to try traversing
the entire node-tree and strip the namespace from everything
:-)</FONT></SPAN></DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff size=2>Or...
go back to the UK government and point out the error of their
ways.</FONT></SPAN></DIV>
<DIV><SPAN class=682210820-10032004><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=682210820-10032004></SPAN> </DIV>
<BLOCKQUOTE>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> jdom-interest-admin@jdom.org
[mailto:jdom-interest-admin@jdom.org]<B>On Behalf Of </B>Martin
Smith<BR><B>Sent:</B> Wednesday, March 10, 2004 12:06 PM<BR><B>To:</B>
'jdom-interest@jdom.org'<BR><B>Subject:</B> [jdom-interest] removing
namespace<BR><BR></FONT></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>Hi
there</FONT></SPAN></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>Via a web service
I am obtaining an xml docuent. When I try and unarshal it with JAXB I
get an UnmarshalException as the xml is not in format required by their own
schema (this is only government web service after all!).</FONT></SPAN></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>So as the change
is minimal, JDom to the rescue. I thought.</FONT></SPAN></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>The problem is
that the element..</FONT></SPAN></DIV><SPAN class=411312818-10032004><!--StartFragment --><PRE id=line36> <<SPAN class=start-tag>ns1:Reference</SPAN><SPAN class=attribute-name> xmlns:ns1</SPAN>=<SPAN class=attribute-value>"http://www.govtalk.gov.uk/gateway/digitalmail"</SPAN>>PRG278</<SPAN class=end-tag>ns1:Reference</SPAN>></PRE>
<DIV><FONT face=Arial size=2>Should <SPAN class=411312818-10032004>not
</SPAN>have the namespace data. It should just look like this..</FONT></DIV><PRE><PRE id=line36> <<SPAN class=start-tag>Reference</SPAN>>PRG278</<SPAN class=end-tag>Reference</SPAN>></PRE></PRE>
<DIV><FONT face=Arial size=2><SPAN class=411312818-10032004>I get the
reference element, and try and remove the namespace using the
following code...</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=411312818-10032004></SPAN></FONT> </DIV><PRE><SPAN class=411312818-10032004> Namespace ns = Namespace.getNameSpace("ns1", <A href="http://www.govtalk.gov.uk/gateway/digitalmail"><FONT color=#000000>http://www.govtalk.gov.uk/gateway/digitalmail</FONT></A>);</SPAN></PRE><PRE><SPAN class=411312818-10032004> Element ref = parent.getChild("Reference", ns );</SPAN></PRE><PRE><SPAN class=411312818-10032004> ref.removeNamespaceDeclaration();</SPAN></PRE>
<DIV><FONT face=Arial size=2><SPAN
class=411312818-10032004></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=411312818-10032004>Doing this does
not change the elements namespace at all.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=411312818-10032004>So instead it
tried this...</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=411312818-10032004></SPAN></FONT> </DIV><PRE><SPAN class=411312818-10032004> ref.setNamespace(Namespace.getNameSpace("")); // or ("","")</SPAN></PRE>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>Which gives
me...</FONT></SPAN></DIV><PRE><SPAN class=411312818-10032004> <Reference xmlns="">PRG278 </Reference></SPAN></PRE>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>Still not
acceptable to JAXB though, itcomplains about the blank name
space.</FONT></SPAN></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial size=2>Please
help!</FONT></SPAN></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2>Martin</FONT></SPAN></DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=411312818-10032004><FONT face=Arial
size=2></FONT> </DIV></SPAN></SPAN><FONT
size=3><BR><BR>***********************************************************************
<BR>This email and any files transmitted with it are confidential and
<BR>intended solely for the use of the individual or entity to whom they
<BR>are addressed. Any unauthorised distribution or copying is strictly
<BR>prohibited. <BR><BR>Whilst Cedar Software Ltd takes steps to prevent the
transmission of <BR>viruses via e-mail, we can not guarantee that any email or
<BR>attachment is free from computer viruses and you are strongly <BR>advised
to undertake your own anti-virus precautions. <BR><BR>Cedar Software Ltd
grants no warranties regarding performance, <BR>use or quality of any e-mail
or attachment and undertakes no <BR>liability for loss or damage, howsoever
caused. <BR><BR>CedAr is a leading UK supplier of Financial, eProcurement,
Performance Management and, following the recent acquisition of Goldenhill
Computer Systems Ltd, HR and Payroll software. Cedars solutions deliver
increased capabilities and offer a direct and measurable financial return on
investment. The company has a customer base of more than 500 organisations in
both the public and private sector. <BR>Particular sector strengths include
Airlines, Business Services,<BR>Education, Emergency Services, Financial
Services, Government, Health, Local Authorities, Not for Profit, Retail and
Utilities. For more<BR>information, please visit www.cedar.com <BR>2003 CedAr
Software Ltd. All Rights Reserved. <BR>Cedar Software Ltd. Incorporation
number
3214465<BR>***********************************************************************<BR></BLOCKQUOTE></FONT></BODY></HTML>