• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Interspering xml declaration error

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Sheriff
Posts: 27525
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The xsl:output 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
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 27525
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic