title: Java: how to wrap all elements with <sometag> in org.w3c.dom?
body: <p>My goal is to wrap every single dom elements (<code>Node.ELEMENT_NODE</code>) on current <code>org.w3c.dom.Document</code> with tag <code>&lt;something style="background-color:red"&gt;&lt;/something&gt;</code>.</p>
  
  <pre><code>public static void main(String[] args){
      org.w3c.dom.DOMDocument doc;
      paintAllNodes(doc, 0);
  }
  
  public static void paintAllNodes(Node node, int level) {
      // Process node
  
      // If there are any children, visit each one
      NodeList list = node.getChildNodes();
      for (int i=0; i&lt;list.getLength(); i++) {
          // Get child node
          Node childNode = list.item(i);        
  
          // Visit child node
          paintAllNodes(childNode, level+1);
      }
  }
  </code></pre>