sb.append(' ').append(attrs.item(i));
Node attr = attrs.item(i); sb.append(' ').append(attr.getNodeName() + "=\"" + attr.getNodeValue() + "\"");
   public static String elementToString(Node n) throws Exception   {      String name = n.getNodeName();      if (name.startsWith("#"))      {         return "";      }      StringBuffer sb = new StringBuffer();      sb.append('<').append(name);      NamedNodeMap attrs = n.getAttributes();      if (attrs != null)      {         for(int i = 0; i < attrs.getLength(); i++)         {            sb.append(' ').append(attrs.item(i));         }      }      NodeList children = n.getChildNodes();      if (children.getLength() == 0)      {         sb.append("/>").append('\n');      }      else      {         sb.append('>').append('\n');         for(int i = 0; i < children.getLength(); i++)         {            sb.append(elementToString(children.item(i)));         }         sb.append("</").append(name).append('>');      }      return sb.toString();   }