SunQuest
           XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 14th, 2003, 03:30 PM
srivalli9 srivalli9 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 48 srivalli9 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 4 sec
Reputation Power: 6
preserving entity references using DOM, JAXP

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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > preserving entity references using DOM, JAXP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway