PDA

View Full Version : HTML markup in XML doc...


bphein1980
10-01-2005, 01:23 AM
I have an XML doc that contains HTML markup, but the page when loaded inputs the straight markup with out transforming the HTML.

For exampl:

<xml>
-<item name="whatever">
--<desc>
---<a href="whatever.html">Link</a><b>Bold</b>
--</desc>
-</item>
</xml>

When the page displays this, it will just be "Link Bold" with no linking or bolding of the text. If I wrap the the contents of <desc> with the CDATA tags, I then get the straight output of "<a href="whatever.html">Link</a><b>Bold</b>". You "SEE" the HTML tags, it does make the text bold of link the text.

Because of relative path issues between IE and Firefox, I am not able to use document() and with the description in its own file.

Anyone have any ideas on how you can get HTML processed inside of an XML document?

rpgfan3233
10-01-2005, 01:58 AM
Using XSLT is probably the best choice.
Great tutorial to get you started: http://www.w3schools.com/xsl/default.asp

Alex Vincent
10-01-2005, 03:32 AM
I hope you mean XHTML. :)

You also might need the XHTML namespace: http://www.w3.org/1999/xhtml

PowerDrift
10-04-2005, 07:25 AM
Well, what you created technically isnt XML.
XML files should start with <?xml>, not <xml>. And there is no need for the ending "</xml>" element unless <xml> is your container, which if that is true, ignore what I just said before.

To use XHTML withing an XML file, you need to have the XHTML namespace in the root element of your XML file.
Once that is done, you then would use XHTML codes like this:<xhtml:a href="...">That would turn into a link just as it would be if the file were HTML. You would then place the words in the tag, and then end it with this (following the example):</xhtml:a>I hoped that helped. And if it didnt, try reading some XML articles. They will tell you everything you need.

KC-Luck
10-04-2005, 04:46 PM
Well, what you created technically isnt XML.
by all technical terms, yes it is xml, he just chose to have the documentElement be named <xml/>.

how you can get HTML processed inside of an XML document?
you need to use XSL as mentioned by rpgfan3233

(your.xml)
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="your.xsl"?>
<xml>
<item name="whatever">
<desc>
<a href="whatever.html">Link</a><b>Bold</b>
</desc>
</item>
</xml>
(your.xsl)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>output document</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<div class="item">
<h3><xsl:value-of select="@name"/></h3>
<div class="desc">
<xsl:copy-of select="desc"/>
</div>
</div>
</xsl:template>
</xsl:stylesheet>

rpgfan3233
10-04-2005, 05:49 PM
you need to use XSL as mentioned by rpgfan3233
I chose to reference XSL because IE doesn't have as much support for XML namespaces as some other browsers. XSL is generally supported, but the support for it is still poor sometimes.

KC-Luck
10-04-2005, 06:52 PM
that and the fact it can't render XHTML via the DOCTYPE? :)