I have an unusual request. I need to generate an xml file that looks for eg., something like below
<?xml version="1.0" encoding="UTF-8"?>
<pk:DeviceInfo xmlns:pk="urn:ietf:params:xml:ns:kyp:pk" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<pk:Manufacturer xmlns:pk="urn:ietf:params:xml:ns:kyp:pk" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
ABC
</pk:Manufacturer>
<pk:SerialNo>123456</pk:SerialNo>
<pk:Model>Model1</pk:Model>
<pk:IssueNo>1</pk:IssueNo>
</pk:DeviceInfo>
I am generating the xml using jdom api. The problem is, even if i declare namespace for pk:Manufacturer element, jdom doesn't add it there because it is already declared in the root element. But i need to repeat the namespace declaration in the child element as well, because i need to send this file to another server that requires the xml to be in this format.
I believe jdom doen't allow this, so i tried to create the xml first with jdom and update the xml with dom parser to include the namespace to the child element using elmt.setAttributeNS(), but unfortunately this doesn't seem to work.
Has anybody faced this problem before?