首页javadomJava HTML/XML - 如何使用DOM提取XML文本...

Java HTML/XML - 如何使用DOM提取XML文本...

我们想知道如何使用DOM提取XML文本。...
  

import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

public class Main {

  public static void copyAttributes(Element from, Element to) {
      NamedNodeMap attributes = from.getAttributes();
      for (int i = 0; i < attributes.getLength(); i++) {
          Attr node = (Attr) attributes.item(i);
          to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue());
      }
  }
}