Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to ignore/skip nodes while parsing xml in Java
    primarykey
    data
    text
    <p>I'm trying to remove <code>SOAP</code> and <code>ns2</code> nodes from this XML :</p> <pre><code>&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt; &lt;SOAP-ENV:Body&gt; &lt;ns2:createCustomer&gt; &lt;Customer&gt; &lt;CustomerId/&gt; &lt;names&gt; &lt;firstName&gt;fName&lt;/firstName&gt; &lt;lastName&gt;lName&lt;/lastName&gt; &lt;middleName&gt;nName&lt;/middleName&gt; &lt;nickName/&gt; &lt;/names&gt; &lt;addressList&gt; &lt;address&gt; &lt;streetInfo&gt; &lt;houseNumber&gt;22&lt;/houseNumber&gt; &lt;baseName&gt;Street base name&lt;/baseName&gt; &lt;district&gt;kewl district&lt;/district&gt; &lt;/streetInfo&gt; &lt;zipcode&gt;22231&lt;/zipcode&gt; &lt;state&gt;xxx&lt;/state&gt; &lt;country&gt;xxxz&lt;/country&gt; &lt;primary&gt;true&lt;/primary&gt; &lt;/address&gt; &lt;/addressList&gt; &lt;SSN&gt;561381&lt;/SSN&gt; &lt;phone&gt; &lt;homePhone&gt;123123123&lt;/homePhone&gt; &lt;officePhone/&gt; &lt;homePhone&gt;21319414&lt;/homePhone&gt; &lt;/phone&gt; &lt;preferred&gt;true&lt;/preferred&gt; &lt;/Customer&gt; &lt;/ns2:createCustomer&gt; &lt;/SOAP-ENV:Body&gt; &lt;/SOAP-ENV:Envelope&gt; </code></pre> <p>Is this possible before this :</p> <pre><code>Document doc = parser.parse(xmlFile); NodeList startlist = doc.getChildNodes(); </code></pre> <p>I tried to read this as String then writing it back to the XML file like this :</p> <pre><code>private void preParsing(String fileName,String ...tags) { try { BufferedReader br = new BufferedReader(new FileReader(new File(fileName))); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { for (String string : tags) { if(!line.contains(string)){ sb.append(line); sb.append("\n"); } } } System.out.println(sb.toString()); br.close(); } catch (IOException e) { System.err.println("Error occured: " + e.getMessage()); } } </code></pre> <p>It worked if I ignore only one tag like :</p> <pre><code>preParsing("src/main/resources/test.xml", "SOAP"); </code></pre> <p>But it didn't work when I pass more than one tag argument to ignore/remove from file. I'm sure there is more elegant way of doing this I just can't think of any. </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