Embedding HTML in XML

I

Isaac Gerg

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

Andy Dingley

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.
 
I

Isaac Gerg

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

Isaac

Andy said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top