Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 14th, 2003, 05:29 PM
Authorized User
 
Join Date: Nov 2003
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default entity references not preserved in XML Output

Hi,
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.
----------
DTD.....
----------
<!ENTITY x "Jones">
<!ELEMENT message (approved, signature )>
<!ELEMENT approved EMPTY>
<!ATTLIST approved flag ( true | false ) "false">
<!ELEMENT signature ( #PCDATA )>

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

-----------
sampleoutput.xml
-----------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE message SYSTEM "sample.dtd">
<message>
<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();
factory.setExpandEntityReferences(true);
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);

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.

Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:16 AM.


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