Note that there are some explanatory texts on larger screens.

plurals
  1. POJAVA prefixing all the elements of an xml
    primarykey
    data
    text
    <p>Is there any way I can prefix each element of my xml in java? For example, I have the following xml:</p> <pre class="lang-xml prettyprint-override"><code> &lt;node1 xmlns="www.test.com"&gt; &lt;node2&gt;abc&lt;/node2&gt; &lt;node3&gt; &lt;node3_1&gt;test1&lt;/node3_1&gt; &lt;/node3&gt; &lt;/node1&gt; </code></pre> <p>I want to convert it to:</p> <pre class="lang-xml prettyprint-override"><code> &lt;test:node1 xmlns test="www.test.com"&gt; &lt;test:node2&gt;abc&lt;/test:node2&gt; &lt;test:node3&gt; &lt;test:node3_1&gt;test1&lt;/test:node3_1&gt; &lt;/test:node3&gt; &lt;/test:node1&gt; </code></pre> <p>Is there an easy way to do this? So far I have tried:</p> <pre><code> String messageString = message.getPayloadAsString(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; Document document = null; try { builder = factory.newDocumentBuilder(); document = builder.parse( new InputSource( new StringReader( messageString) ) ); } catch (Exception e) { e.printStackTrace(); } XmlObject inboundMessageObject = XmlObject.Factory.parse(document); XmlOptions xmlOptions = new XmlOptions(); Map&lt;String, String&gt; namespaceMap = new HashMap&lt;String, String&gt;(); namespaceMap.put("www.test.com", "test"); xmlOptions.setSaveSuggestedPrefixes(namespaceMap); xmlObject.save(System.out, xmlOptions); String prefixedXML = inboundMessageObject.xmlText(xmlOptions); return prefixedXML; </code></pre> <p>What I see is, the prefixedXML String is the same as the messageString string.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload