Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 14th, 2003, 05:29 PM
Authorized User
Join Date: Nov 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default entity references not preserved in XML Output

I have an XML file, an element of which refers to a general entity.
I'm using DOm parser and JAXP API to parse it and form a resulting XML file.
I want the entity reference to be preserved in the resulting XML file which is currently NOT.
<!ENTITY x "Jones">
<!ELEMENT message (approved, signature )>
<!ELEMENT approved EMPTY>
<!ATTLIST approved flag ( true | false ) "false">
<!ELEMENT signature ( #PCDATA )>

<?xml version="1.0" ?>
<!DOCTYPE message SYSTEM "sample.dtd">
<approved flag="true"/>
<signature>Chairperson &x; PhD</signature>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE message SYSTEM "sample.dtd">
<approved flag="true"/>
<signature>Chairperson Jones PhD</signature>
</message> <....>

I DO NOT want Jones. Instead, I want it as &x;
That is, I want to have the exact same XML output as the SOURCE.

My JAVA code follows....
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();

DocumentBuilder builder=factory.newDocumentBuilder();
builder.setErrorHandler(new MyErrorHandler());
document=builder.parse(new File("C:/sample.xml"));

TransformerFactory tf=TransformerFactory.newInstance();
Transformer t=tf.newTransformer();
t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "sample.dtd");

FileWriter fileOut = new FileWriter("sampleoutput.xml");
t.transform(new DOMSource(document), new StreamResult(fileOut));

sample.xml -- source XML
sampleoutput.xml -- output XML
sample.dtd -- DTD

Could anyone please figure out how to preserve entity references?
Any help in this regard is grately appreciated.

- Srivalli.

Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:output with encoding and UPPER case entity ROCXY XSLT 1 April 19th, 2007 08:20 AM
preserving entity references muki XSLT 6 March 7th, 2006 12:08 PM
Entity References and DOM boemane C# 0 August 24th, 2004 08:21 AM
preserving entity references using DOM, JAXP srivalli9 XML 2 November 17th, 2003 11:00 AM
Output a newline entity reference quivogne XSLT 4 October 1st, 2003 01:37 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.