• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Failed to set external entity into CDATA

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a non-xml file which need to be included in a xml file.

I use external entity to include the non-xml file, but it doesn't affect to set external entity to CDATA.

Here are my files.

[xml-file]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script [
<!ENTITY datepicker SYSTEM "datepicker.js">
]>

<script>
<body>
<![CDATA[
&datepicker;
]]>
</body>
</script>
[xml-file]

[non-xml-file]
function getScroll () {
if (document.all && typeof document.body.scrollTop != "undefined") {// IE model
var ieBox = document.compatMode != "CSS1Compat";
var cont = ieBox ? document.body : document.documentElement;
return {
left:cont.scrollLeft,
top:cont.scrollTop,
width:cont.clientWidth,
height:cont.clientHeight
};
}
else {
return {
left:window.pageXOffset,
top:window.pageYOffset,
width:window.innerWidth,
height:window.innerHeight
};
}

}
[non-xml-file]


Best regards,
Leon
 
Marshal
Posts: 28226
95
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
What makes you think that entity references in CDATA should be expanded? I don't see where in the XML recommendation it says that, and in fact it says about CDATA sections that they are "used to escape blocks of text containing characters which would otherwise be recognized as markup". My Google search for "external entity cdata" turned up a couple of other newsgroup posts about that topic including this response:

http://mail.python.org/pipermail/xml-sig/2001-May/005525.html

from someone who wrote an XSLT processor so presumably knows what he's talking about.
 
Leon Pu
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also got the mail-list, but I cannot understand the meaning.

I also found an article which describes use CDATA inside <!ENTITY>. But it is impossibile to put CDATA inside <!ENTITY>, at least in my IE environment, only NDATA is allowed.

http://www.oasis-open.org/cover/english-cdata.html#SEC4

I just wonder why it cannot put non-xml entity into CDATA. Use NDATA you can handle jsp or postscript file. It should be easy to convert the non-xml entity to xml acceptable CDATA content.
 
Paul Clapham
Marshal
Posts: 28226
95
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 "why" part wasn't obvious to me either. But Uche's advice in that mail-list link was pretty clear: just don't put the entity reference inside CDATA. It looks like that would be extremely simple to do in your example.
 
Leon Pu
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
The "why" part wasn't obvious to me either. But Uche's advice in that mail-list link was pretty clear: just don't put the entity reference inside CDATA. It looks like that would be extremely simple to do in your example.



Do you mean the following content from Uche's mail-list?

Unfortunately there is no easy solution. You'd have to wrap all the entities in ]]>&entity;<![CDATA[



But it doesn't work at all. "&entity;" is still non-xml content.

Is there any other way to import non-xml file to xml? Maybe external entity is a dead way, or import non-xml as xml content is impossible.
 
Paul Clapham
Marshal
Posts: 28226
95
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
Oh, I see. After messing about with those files for a bit I suddenly realized what your original question was. (The one for which your answer was "Let's wrap this in a CDATA section.") It was "How do I put text into an XML document if it makes that document not well-formed XML?" I didn't notice that the point of the question was that there were ampersands in the javascript.

Well, I think the answer is to make it well-formed. Either escape the ampersands (per the XML rules) or put the <![CDATA[...]]> brackets around the text in the datepicker.js file. Either of those works for me in the sense that it results in well-formed XML that can be parsed and transformed.

Are you going to say you can't do that because then it won't be correct javascript? You may be right. But if you are right then it would be impossible to embed that javascript in an XHTML file, which I suspect is not the case. I don't generally embed scripts in HTML so I don't know the rule, but surely there is a rule for embedding javascript in XHTML. If there is, I would bet it involves escaping ampersands. But as I said, I don't know.
 
Leon Pu
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
Oh, I see. After messing about with those files for a bit I suddenly realized what your original question was. (The one for which your answer was "Let's wrap this in a CDATA section.") It was "How do I put text into an XML document if it makes that document not well-formed XML?" I didn't notice that the point of the question was that there were ampersands in the javascript.

Well, I think the answer is to make it well-formed. Either escape the ampersands (per the XML rules) or put the <![CDATA[...]]> brackets around the text in the datepicker.js file. Either of those works for me in the sense that it results in well-formed XML that can be parsed and transformed.

Are you going to say you can't do that because then it won't be correct javascript? You may be right. But if you are right then it would be impossible to embed that javascript in an XHTML file, which I suspect is not the case. I don't generally embed scripts in HTML so I don't know the rule, but surely there is a rule for embedding javascript in XHTML. If there is, I would bet it involves escaping ampersands. But as I said, I don't know.



Thank you for your hint Paul.

I found the answer in following url.

http://www.codehouse.com/javascript/tips/xhtml/
 
reply
    Bookmark Topic Watch Topic
  • New Topic