Embedding HTML in XML

Discussion in 'XML' started by Isaac Gerg, Oct 5, 2004.

  1. Isaac Gerg

    Isaac Gerg Guest

    I have a server running PHP on linux. For a website, I want to have the
    webdocuments stored in XML, then parsed by PHP code to add the
    appropriate titles, headers, menus, etc.

    So, I want to embed some HTML into XML. Can I do this? If so, what
    functions do I use to parse this? Below is an example XML doc.

    <xml>
    <title>Document Title</title>
    <menu level="2">
    <item>Home</item>
    <item>Products</item>
    </menu>
    <content>
    <p>
    Now introduction, our <B>NEW</B> product line!
    </content>
    </xml>


    The php will parse title and menu easily... but how i can i get it to
    return 'content' as a string which includes all that HTML?

    Any help deeply appreciated.
    Isaac Gerg, Oct 5, 2004
    #1
    1. Advertising

  2. Isaac Gerg

    Andy Dingley Guest

    On Tue, 05 Oct 2004 12:12:37 -0400, Isaac Gerg
    <> wrote:

    >So, I want to embed some HTML into XML. Can I do this?


    Yes. There are several ways to do it. You will find it useful to study
    RSS, which had to address a similar problem (unfortunately not
    particularly well). There's an interesting overview of it here
    http://diveintomark.org/archives/2004/02/04/incompatible-rss
    You can probably even find PHP code to help you do this, by looking at
    RSS tools

    If you want to embed HTML, then you have two main options; encoding
    and CDATA. Encoding is often simpler.

    [...]
    <content>
    &lt;p&gt;
    Now introduction, our &lt;B&gt;NEW&lt;/B&gt; product line!
    </content>
    [...]

    Note that encoding the HTML entity reference "&lt;" will need to
    appear as "&amp;lt;"


    or as CDATA
    [...]
    <content><![CDATA[
    <p>
    Now introduction, our <B>NEW</B> product line!
    ]]></content>
    [...]

    Note that the sequence ]]> in your HTML (an embedded CDATA section)
    will need some special handling too.



    If you can abandon HTML in favour of XHTML though, there's a much
    better solution available; namespacing. If you control the HTML part
    of the process yourself, I'd see this as a good reason to switch to
    XHTML.

    --
    Smert' spamionam
    Andy Dingley, Oct 6, 2004
    #2
    1. Advertising

  3. Isaac Gerg

    Isaac Gerg Guest

    I choose to use CDATA for those intersted. See http://www.gergltd.com

    Isaac

    Andy Dingley wrote:

    > On Tue, 05 Oct 2004 12:12:37 -0400, Isaac Gerg
    > <> wrote:
    >
    >
    >>So, I want to embed some HTML into XML. Can I do this?

    >
    >
    > Yes. There are several ways to do it. You will find it useful to study
    > RSS, which had to address a similar problem (unfortunately not
    > particularly well). There's an interesting overview of it here
    > http://diveintomark.org/archives/2004/02/04/incompatible-rss
    > You can probably even find PHP code to help you do this, by looking at
    > RSS tools
    >
    > If you want to embed HTML, then you have two main options; encoding
    > and CDATA. Encoding is often simpler.
    >
    > [...]
    > <content>
    > &lt;p&gt;
    > Now introduction, our &lt;B&gt;NEW&lt;/B&gt; product line!
    > </content>
    > [...]
    >
    > Note that encoding the HTML entity reference "&lt;" will need to
    > appear as "&amp;lt;"
    >
    >
    > or as CDATA
    > [...]
    > <content><![CDATA[
    > <p>
    > Now introduction, our <B>NEW</B> product line!
    > ]]></content>
    > [...]
    >
    > Note that the sequence ]]> in your HTML (an embedded CDATA section)
    > will need some special handling too.
    >
    >
    >
    > If you can abandon HTML in favour of XHTML though, there's a much
    > better solution available; namespacing. If you control the HTML part
    > of the process yourself, I'd see this as a good reason to switch to
    > XHTML.
    >
    Isaac Gerg, Oct 7, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin
    Replies:
    1
    Views:
    492
    Martin Honnen
    Dec 17, 2003
  2. Mark Van Orman

    embedding xml in xml as non-xml :)

    Mark Van Orman, Sep 14, 2004, in forum: XML
    Replies:
    5
    Views:
    466
    Patrick TJ McPhee
    Sep 15, 2004
  3. Replies:
    1
    Views:
    576
    Travis Newbury
    Sep 13, 2006
  4. DartGuru
    Replies:
    4
    Views:
    2,681
    Chaddy2222
    Oct 23, 2007
  5. Replies:
    5
    Views:
    530
Loading...

Share This Page