PRESERVING ENTITY REFERENCES IN OUTPUT xml
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Srivalli_Chavali
Posted On:   Friday, November 14, 2003 01:41 PM

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&   More>>

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" ?>







Chairperson &x; PhD





-----------

sampleoutput.xml

-----------

<?xml version="1.0" encoding="UTF-8"?>







Chairperson Jones PhD

<....>



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.

   <<Less
About | Sitemap | Contact