php_brian
03-19-2003, 02:22 AM
I am using DTD's to validate my XML document using PHP with Expat. Well, the issue is that I am trying have an element with data that could be parsable, but I want the DTDs to tell Expat to not parse it and ignore it with out using entities.
For example:
<section>Hey people, check this code out <pre>var i = 0;</pre></section>
So it will ignore that it is there and just send to the PHP script as is. Any ideas on how it could be done with the DTDs? Thanks.
brothercake
03-19-2003, 03:04 PM
It can't be done with DTD; maybe with XSD, but I don't know about that.
Anyway I thought that's what CDATA sections are for:
<section>
Hey people, check this code out
<![CDATA[
<pre>var i=0;</pre>
]]>
</section>
cg9com
03-19-2003, 06:55 PM
i thought CDATA was going to replace the comment tag.
brothercake
03-19-2003, 10:48 PM
it amounts to the same thing - anything inside a CDATA section is ignored by the parser, even non-entity < and > symbols. But hmmm ... not sure if that means it can be dumped as output text in transformations, or whether it's just a comment that can't be transformed. You'd have to try it and see.
But either way, DTD won't help you here - DTD cannot control what kind of data is allowed inside an element, only whether it's CDATA, PCDATA or a combination of those two plus other elements. XSD, I think, can do this - but I know almost nothing about XSD.
And in any case ... this whole thing about putting entity-HTML inside XML is strange; I see it a lot, particularly in weblogs - an XML node with HTML inside it which is supposed to be parsed as literal HTML inside the transformed node. But my opinion is that this is sloppy XML; you should not add visual markup or attempt to imply formatting within data XML.
What you can do, to get a proper solution to this, is make the <pre/> node a real XML node - cite it in your DTD and then parse it into an HTML <pre/> element in when you're generating your page.