10 Serialize Dom

<..static String serialize( dom )..>
 static String serialize( Node root ){
    if( root.getNodeType() == Node.TEXT_NODE) {
          return root.getNodeValue();
    }
    if( root.getNodeType() == Node.ELEMENT_NODE) {
       String ser = "";
       String tagName = root.getNodeName();
       ser += "<" + tagName;
       <.res += serialize attributes.>
       ser += "\n>";
       <.res += serialize children.>
       ser += "</" + tagName + ">";
       return ser;
    }
    if( root.getNodeType() == Node.DOCUMENT_NODE) {
       String ser = "";
       <.res += serialize children.>
       return ser;
    }
    if( root == null ){ return "null"; }
    return "";
 }
 -_-_-

<..res += serialize children..>
 NodeList children = root.getChildNodes();
 if(children.getLength() > 0) {
    for(int i = 0; i < children.getLength(); i++) {
       ser += serialize(children.item(i));
 }  }
 -_-_-

<..res += serialize attributes..>
 NamedNodeMap attributes = root.getAttributes();
 for(int i = 0; i < attributes.getLength(); i++) {
    Attr attribute = (Attr) attributes.item(i);
    ser += "\n" + attribute.getName() + "=\""
                + attribute.getValue() + "\" ";
 }
 -_-_-

 10.1 Clean Xmlns
 10.2 Default Script