[jdom-interest] removing namespace
Day, Jem BGI SF
Jem.Day at barclaysglobal.com
Wed Mar 10 12:11:25 PST 2004
Martin,
I believe the FAQ on the JDOM site has some info regarding namespaces.
If you remove the namespace from a 'parent' element then any child elements will have the xmlns="" representation when output.
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 :-)
Or... go back to the UK government and point out the error of their ways.
-----Original Message-----
From: jdom-interest-admin at jdom.org [mailto:jdom-interest-admin at jdom.org]On Behalf Of Martin Smith
Sent: Wednesday, March 10, 2004 12:06 PM
To: 'jdom-interest at jdom.org'
Subject: [jdom-interest] removing namespace
Hi there
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!).
So as the change is minimal, JDom to the rescue. I thought.
The problem is that the element..
<ns1:Reference xmlns:ns1="http://www.govtalk.gov.uk/gateway/digitalmail">PRG278</ns1:Reference>
Should not have the namespace data. It should just look like this..
<Reference>PRG278</Reference>
I get the reference element, and try and remove the namespace using the following code...
Namespace ns = Namespace.getNameSpace("ns1", <http://www.govtalk.gov.uk/gateway/digitalmail> http://www.govtalk.gov.uk/gateway/digitalmail);
Element ref = parent.getChild("Reference", ns );
ref.removeNamespaceDeclaration();
Doing this does not change the elements namespace at all.
So instead it tried this...
ref.setNamespace(Namespace.getNameSpace("")); // or ("","")
Which gives me...
<Reference xmlns="">PRG278 </Reference>
Still not acceptable to JAXB though, itcomplains about the blank name space.
Please help!
Martin
***********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. Any unauthorised distribution or copying is strictly
prohibited.
Whilst Cedar Software Ltd takes steps to prevent the transmission of
viruses via e-mail, we can not guarantee that any email or
attachment is free from computer viruses and you are strongly
advised to undertake your own anti-virus precautions.
Cedar Software Ltd grants no warranties regarding performance,
use or quality of any e-mail or attachment and undertakes no
liability for loss or damage, howsoever caused.
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.
Particular sector strengths include Airlines, Business Services,
Education, Emergency Services, Financial Services, Government, Health, Local Authorities, Not for Profit, Retail and Utilities. For more
information, please visit www.cedar.com
2003 CedAr Software Ltd. All Rights Reserved.
Cedar Software Ltd. Incorporation number 3214465
***********************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20040310/bbf41145/attachment.htm
More information about the jdom-interest
mailing list