App下載
首頁(yè)javadomJava HTML/XML - 如何獲取DOM文檔中實(shí)體引用的值

Java HTML/XML - 如何獲取DOM文檔中實(shí)體引用的值

我們想知道如何獲取DOM文檔中實(shí)體引用的值。
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.EntityReference;
import org.xml.sax.InputSource;

public class Main {
  public static String getXMLData() {
    return "your data";
  }

  public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = factory.newDocumentBuilder().parse(
        new InputSource(new StringReader(getXMLData())));

    Element root = doc.getDocumentElement();
    EntityReference eref = (EntityReference) root.getFirstChild();

  }

}