void getAttributes(Object node, String localName, String namespaceUri, List result) {
   if (node instanceof Element) {
     Element e = (Element) node;
     if (localName == null) {
       result.addAll(e.getAttributes());
     } else {
       Attribute attr = e.getAttribute(localName, Namespace.getNamespace("", namespaceUri));
       if (attr != null) {
         result.add(attr);
       }
     }
   } else if (node instanceof ProcessingInstruction) {
     ProcessingInstruction pi = (ProcessingInstruction) node;
     if ("target".equals(localName)) {
       result.add(new Attribute("target", pi.getTarget()));
     } else if ("data".equals(localName)) {
       result.add(new Attribute("data", pi.getData()));
     } else {
       result.add(new Attribute(localName, pi.getValue(localName)));
     }
   } else if (node instanceof DocType) {
     DocType doctype = (DocType) node;
     if ("publicId".equals(localName)) {
       result.add(new Attribute("publicId", doctype.getPublicID()));
     } else if ("systemId".equals(localName)) {
       result.add(new Attribute("systemId", doctype.getSystemID()));
     } else if ("elementName".equals(localName)) {
       result.add(new Attribute("elementName", doctype.getElementName()));
     }
   }
 }