-1

I have below xml. Namespace is missing in the below xml.

<?xml version="1.0" encoding="UTF-8"?>
<policy>
  <num-drivers>123</num-drivers>
  <risk-policy-ind>false</risk-policy-ind>
  <premium-amt>23.00</premium-amt>
</policy>

Looking for java code to take the above xml as input and add namespace (xmlns) element to it? The expected output xml is as below:

<?xml version="1.0" encoding="UTF-8"?>
<policy xmlns="http://aaa.bbb.com">
  <num-drivers>123</num-drivers>
  <risk-policy-ind>false</risk-policy-ind>
  <premium-amt>23.00</premium-amt>
</policy>
ams2705
  • 287
  • 2
  • 5
  • 17
  • Are these answers sufficient? http://stackoverflow.com/questions/528312/creating-an-xml-document-using-namespaces-in-java – Steinar Feb 18 '13 at 23:30

1 Answers1

0

First of all, in the above xml, risk-policy-ind tag is not properly closed. In XML all tags are custom tags, they should close. Moreover,in xml, tags are performed without namespace.

If u just want to add xmlns attribute to policy tag, create policy element using w3c.dom.Element and set attribute using setAttribute function

raj
  • 387
  • 2
  • 9