title: Convert xml with namespaces to json in java
body: <p>I'm trying to convert xml to json using java and then convert the json back to xml after modifying which should give the same xml. The xml attributes have namespaces.</p>
  
  <p>My sample xml : </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ns2:testplan xmlns:ns2="http://jazz.net/xmlns/alm/qm/v0.1/" xmlns:ns1="http://schema.ibm.com/vega/2008/" xmlns:ns3="http://purl.org/dc/elements/1.1/" xmlns:ns4="http://jazz.net/xmlns/prod/jazz/process/0.6/" xmlns:ns5="http://jazz.net/xmlns/alm/v0.1/" xmlns:ns6="http://purl.org/dc/terms/" xmlns:ns7="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ns8="http://jazz.net/xmlns/alm/qm/v0.1/testscript/v0.1/" xmlns:ns9="http://jazz.net/xmlns/alm/qm/v0.1/executionworkitem/v0.1" xmlns:ns10="http://open-services.net/ns/core#" xmlns:ns11="http://open-services.net/ns/qm#" xmlns:ns12="http://jazz.net/xmlns/prod/jazz/rqm/process/1.0/" xmlns:ns13="http://www.w3.org/2002/07/owl#" xmlns:ns14="http://jazz.net/xmlns/alm/qm/qmadapter/v0.1" xmlns:ns15="http://jazz.net/xmlns/alm/qm/qmadapter/task/v0.1" xmlns:ns16="http://jazz.net/xmlns/alm/qm/v0.1/executionresult/v0.1" xmlns:ns17="http://jazz.net/xmlns/alm/qm/v0.1/catalog/v0.1" xmlns:ns18="http://jazz.net/xmlns/alm/qm/v0.1/tsl/v0.1/" xmlns:ns20="http://jazz.net/xmlns/alm/qm/styleinfo/v0.1/" xmlns:ns21="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;ns2:projectArea href="https://testserver:9080/qm/resource/itemOid/com.ibm.team.process.ProjectArea/_xv6jsJceEeimbPqnRT_G_Q" alias="projectArea"/&gt;
  &lt;ns3:identifier&gt;https://testserver:9080/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/projectArea/testplan/urn:com.ibm.rqm:testplan:70?revision=294&lt;/ns3:identifier&gt;
  &lt;ns2:stylesheet href="https://testserver:9080/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/projectArea/testplan/urn:com.ibm.rqm:testplan:70?stylesheet=true"/&gt;
  &lt;ns2:snapshot&gt;
  &lt;ns3:title&gt;testplan_70_&amp;lt;Reason&amp;gt;_&amp;lt;Version&amp;gt;_on_16 Apr 2019 05:50&lt;/ns3:title&gt;
  &lt;ns5:updated&gt;2019-04-16T12:20:01.644Z&lt;/ns5:updated&gt;
  &lt;ns2:revision&gt;294&lt;/ns2:revision&gt;
  &lt;/ns2:snapshot&gt;
  &lt;ns2:webId&gt;70&lt;/ns2:webId&gt;
  &lt;ns3:title&gt;Demo test plan 06&lt;/ns3:title&gt;
  &lt;ns3:description/&gt;
  &lt;ns2:creationDate&gt;2019-01-22T10:36:40.289Z&lt;/ns2:creationDate&gt;
  &lt;ns5:updated&gt;2019-04-16T12:20:01.644Z&lt;/ns5:updated&gt;
  &lt;ns5:state ns7:resource="https://testserver:9080/qm/service/com.ibm.rqm.integration.service.IIntegrationService/process-info/_xv6jsJceEeRT_G_Q/workflowstate/com.ibm.rqm.process.testplan.workflow/com.ibm.rqm.planning.common.underreview"&gt;com.ibm.rqm.planning.common.underreview&lt;/ns5:state&gt;
  &lt;ns3:creator ns7:resource="https://testserver:9080/jts/resource/itemName/com.ibm.team.repository.Contributor/JLO1COB"&gt;abc&lt;/ns3:creator&gt;
  &lt;ns5:owner&gt;unassigned&lt;/ns5:owner&gt;
  &lt;ns2:priority ns7:resource="https://testserver:9080/qm/service/com.ibm.rqm.integration.service.IIntegrationService/process-info/_xv6jsJceEeimbPqnG_Q/priority/literal.priority.101"&gt;literal.priority.101&lt;/ns2:priority&gt;
  &lt;ns2:locked&gt;false&lt;/ns2:locked&gt;
  &lt;ns2:component href="https://testserver:9080/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/projectArea/component/_yzQ3EZcmbPqnRT_G_Q"/&gt;
  &lt;/ns2:testplan&gt;
  </code></pre>
  
  <p>Could someone please help me to convert preciously using java.</p>
  
  <p>I have tried converting using org.json.XML, But it was not giving proper json with jsonobject keys/values having namespaces.</p>
  
  <p>Code I have tried and not giving response: </p>
  
  <pre><code>JSONObject jsonObject = XML.toJSONObject("xml");
  </code></pre>
  
  <p>I expect a convertion way which gives Json with proper format and json objects having namespaces,and If I covert this json it should give initial xml
  Please help me.</p>