Hi all,
   I am using Xerces-J 2.9.1.

I need to create a simple XML document using DOM APIs. The XML will
have an internal DTD subset, declaring an entity.

[1] Following is the XML I want to create (in this lexical form only):

<?xml version="1.0"?>
<!DOCTYPE root [
  <!ENTITY x "hello">
]>
<root>
  <a>&x; world</a>
</root>

The program I have written so far is:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = dbf.newDocumentBuilder();

Document document = docBuilder.newDocument();

Element root = document.createElement("root");
Element a = document.createElement("a");
root.appendChild(a);
EntityReference x = document.createEntityReference("x");
a.appendChild(x);
a.appendChild(document.createTextNode(" world"));

DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS)registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
LSOutput output = impl.createLSOutput();
output.setByteStream(System.out);
writer.write(root, output);

This produces output:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <a>&x; world</a>
</root>

But I want to have an internal DTD subset as well (as shown in [1] above).

What could I do to achieve this?

I would be thankful for the help to solve this problem.


-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to