Java Document .createEntityReference (String name)

Syntax

Document.createEntityReference(String name) has the following syntax.

EntityReference createEntityReference(String name)     throws DOMException

Example

In the following code shows how to use Document.createEntityReference(String name) method.


import java.io.StringReader;
/*from   w  ww . j  a v  a2s. c om*/
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

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

public class Main {
  public static void main(String args[]) throws Exception{
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();  // Create the parser
    Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString)));

    EntityReference ref = xmlDoc.createEntityReference("name") ;
    
  }
  static String xmlString ="<?xml version=\"1.0\"?>" +
      "  <address id='asdf'>" +
      "    <buildingnumber> 29 </buildingnumber>" +
      "    <street> South Street</street>" +
      "    <city>Vancouver</city>" +
      "" +
      "    <state>BC</state>" +
      "    <zip>V6V 4U7</zip>" +
      "  </address>";
}




















Home »
  Java Tutorial »
    org.w3c.dom »




CharacterData
Document
NodeList