aspose file tools*
The moose likes XML and Related Technologies and the fly likes Interspering xml declaration error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Interspering xml declaration error" Watch "Interspering xml declaration error" New topic
Author

Interspering xml declaration error

Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi All,

How can I acheive this. I am currently using xsl for xml to xml transformation. The new xml generated is forwarded to a method which carries out the xml parsing (confirms to DTD check).

In order to acheive that I need to interspere the DTD reference as XML declaration in the newly generated xml.

This is what I need to add in the start of every xml payload generated.
*********************************
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE destination SYSTEM "world.dtd" [
<!ENTITY euro "Euro">
]>
************************************

Here is the xsl which I use to render the xml & I need the above xml declaration included

--------------------------------------------------

<xsl:template match="arts">

<tag1>
blah blah
</tag1>

<tag2>
blah blah
</tag2>

</xsl:template>


<xsl:template match="article">

<tag11>
blah blah
</tag11>

<tag22>
blah blah
</tag22>

</xsl:template>
--------------------------------------------------

I tried to include a call template routine but was not of much help

--------------------------------------------------
<xsl:template name="wrapper" match="wrapper">

<xsl:param name="content"/>

<xsl:text>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE destination SYSTEM "world.dtd" [
<!ENTITY euro "Euro">
]>


</xsl:text>
<xsl:copy-of select="$content"/>

</xsl:template>
--------------------------------------------------

But when I run this I get the following error

org.xml.sax.SAXParseException: XML declaration may only begin entities.


Do post your thoughts on the same


Regards,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The xslutput element has a "doctype-system" attribute that you can use to make the transformer generate the first line of that DTD. As for the second line, I don't see the point in putting it there at all. Your transformer isn't going to put "&euro;" anywhere in the output document, it's going to write the actual Unicode character for the euro symbol.
Mohit Sinha
Ranch Hand

Joined: Nov 29, 2004
Posts: 125
Hi Paul,

Thanks for your response.

The xml which I create after xsl transformation is rendered to an external application.
The DTD is published by the external app which I have to adhere to.
They expect every xml payload which i will be passing to their application having the below mentioned xml declaration

--------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE destination SYSTEM "world.dtd" [
<!ENTITY euro "Euro">
]>
--------------------------------

I am not much into xml. Sorry if this question sounds naive.
Does it mean that I can ignore the
[<!ENTITY euro "Euro">]>

& create the xml payload just by appending the following xml declaration
<?xml version="1.0" encoding="UTF-8"?>
to every payload I generate.


Do post your comments on the same


Regards,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, I am not much of a DTD expert either. But I am pretty sure that the entity definition is there just so that somebody at a keyboard can type
&euro;
instead of having to remember that the Euro character is Unicode character 20A0 and having to type
&#x20A0;
This sort of thing is not an issue when it's a computer generating the XML, and in fact I don't even know if it's possible to get an XML serializer (the code that takes an internal form like a DOM and makes it into a text document) to use entities like that. So the serializer won't be putting &euro; into the document, and therefore the entity declaration doesn't do anything.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interspering xml declaration error