Reputation: 78183
I'm trying to produce a valid XHTML document from XML data.
I'm doing so using MSXML object library, not .NET. With .NET there are no problems, transforms just fine.
My XSL template has this:
<xsl:output
method="xml"
omit-xml-declaration="no"
indent="no"
version="1.0"
encoding="utf-8"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
/>
Then goes:
<xsl:template match="/root">
<html xmlns="http://www.w3.org/1999/xhtml">
...
</html>
</xsl:template>
And there come problems.
If I use MSXML2.DOMDocument40, MSXML refuses to generate the XHTML because
The attribute '{xmlns}' on this element is not defined in the DTD/Schema.
Apparenty, one of the HTML tags in the template body is not allowed to have the namespace it inherits from <html>
. But MSXML won't tell me which tag that is.
If I just strip out everything from the template and dump the XML data enclosed in <p>
, then it transforms fine. Apparently, <p>
is allowed to have xmlns
.
What tag is that, which ruins everything for me?
If I use MSXML2.DOMDocument60, I first have to say:
xmlTransformedResult.setProperty("ProhibitDTD", False)
, otherwise I get "DTD is prohibited."
Having that setting set, I get:
The element 'html' is used but not declared in the DTD/Schema.
How can I fix that?
If I use .NET transformation, it's all fine. The generated document starts with
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Now, I can remove both doctype-public
and doctype-system
from the template, produce just plain XML, and then manually prepend the header to it. But I don't wan't to. What is the proper way of making this work?
Upvotes: 2
Views: 3170
Reputation: 167696
I think the problem with MSXML 6 is that by default it neither allows DTDs nor it loads them (or any external resources in general). So to avoid the validation message you need to set both (I am using JScript syntax, please adjust to your language of choice):
xmlTransformedResult.resolveExternals = true;
xmlTraansformedResult.setProperty('ProhibitDTD', false);
Then I think you won't get the validation error. At least as long as the W3C is going to serve up the XHTML DTD files, I think when you do that programmatically a lot you might get errors but that does not depend on MSXML, that is simply a W3C policy to avoid too much traffic on their servers by everyone fetching such DTDs.
Upvotes: 1