Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: XML and DTDs

  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Location
    Denver, CO
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XML and DTDs

    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.
    Brian A Rosner

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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>
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    Senior Coder
    Join Date
    Jul 2002
    Posts
    1,628
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i thought CDATA was going to replace the comment tag.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by brothercake; 03-19-2003 at 11:00 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •