Embedding HTML in XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Isaac Gerg

    #1

    Embedding HTML in XML

    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>Docume nt Title</title>
    <menu level="2">
    <item>Home</item>
    <item>Product s</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.
  • Andy Dingley

    #2
    Re: Embedding HTML in XML

    On Tue, 05 Oct 2004 12:12:37 -0400, Isaac Gerg
    <isaac.gerg@NOS PAM-adelphia.net> wrote:
    [color=blue]
    >So, I want to embed some HTML into XML. Can I do this?[/color]

    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

    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

    Comment

    • Isaac Gerg

      #3
      Re: Embedding HTML in XML

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

      Isaac

      Andy Dingley wrote:
      [color=blue]
      > On Tue, 05 Oct 2004 12:12:37 -0400, Isaac Gerg
      > <isaac.gerg@NOS PAM-adelphia.net> wrote:
      >
      >[color=green]
      >>So, I want to embed some HTML into XML. Can I do this?[/color]
      >
      >
      > 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/200...compatible-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.
      >[/color]

      Comment

      Working...