Page 1 of 1

cvc-complex-type.2.4.d validation error

Posted: Sat Jan 21, 2006 1:38 am
by Andreas Kemkes
I'm evaluating oXygen and get the following validation error:

cvc-complex-type.2.4.d: Invalid content was found starting with element 'p'. No child element is expected at this point. @see: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type

I'm not entirely clear on what is wrong.

The section of the document that fails to validate is

Code: Select all


<slideText>
<p>....</p>
</slideText>
using the following XML Schema definition

Code: Select all


<xs:element name="slideText" type="text.type"/>

<xs:complexType name="text.type" mixed="true">
<xs:complexContent>
<xs:restriction base="xhtml:Flow"/>
</xs:complexContent>
</xs:complexType>
This same combination validates in a competing tool.

My questions are:
(1) Is the other tool too linient?
(2) What can I change to make the file validate in oXygen?

Thank you in advance for your help.

Andreas

Posted: Sat Jan 21, 2006 10:04 am
by george
Hi Andreas,

I cannot say exactly what is wrong based only on these fragments. Anyway a guess is that you need to enter p from the xhtml namespace while in your instance document you have p from the same namespace as your slideText element.

From:
<slideText>
<p>....</p>
</slideText>
both p and slideText are in the default namepspace for your document as they have no prefix.

From:
<xs:element name="slideText" type="text.type"/>
<xs:complexType name="text.type" mixed="true">
<xs:complexContent>
<xs:restriction base="xhtml:Flow"/>
</xs:complexContent>
</xs:complexType>

the slideText is defined in the current schema target namespace and the content is xhtml:Flow. Now assumming the current schema target namespace is different from the xhtml namespace then the problem is my guess above.

If that does not solve your problem please consider posting a more complete example (cut down as much as possible).

Please note that you can also validate with external validators in oXygen 7 like Saxon SA, XSV, LIBXML. MSXML, System.XML, SQC.

Best Regards,
George

Posted: Tue Jan 24, 2006 4:44 am
by Andreas Kemkes
George:

Thank you. That got me on the right track - I also had to change the <xs:restriction> to a <xs:extension>. Thinking about it, I'm somewhat surprised that the other tool would be so lenient and validate the document.

So now I have

Code: Select all


<slideText> 
<xhtml:p>....</xhtml:p>
</slideText>
and everything validates, but what I really would like to do is to keep writing

Code: Select all


<slideText> 
<p>....</p>
</slideText>
and still only allow xhtml:Flow. Is that even possible? I guess I have to do some more research if and how it is possible to pull that part of XHTML into my namespace. Pointers are very welcome, though. Thanks again.

Regards,

Andreas

Posted: Tue Jan 24, 2006 10:43 am
by george
Hi Andreas,

If the xhtml elements stay in their namespace then it is not possible to have their namespace changed. You can write for instance:

Code: Select all


slideText>
<p xmlns="http://www.w3.org/1999/xhtml">
<font size="10">.....</font>
</p>
</slideText>
That is you can declare the xhtml namespace as default namespace.

If the schema for xhtml that you use defines for instance the Flow complex type and the elements that go inside this type in a schema document with an absent targetNamespace then you can include that schema document from your schema and thus have the components inherit the target namespace of your including schema.
The schema with an absent target namespace included from a schema with a target namespace is generally called a chameleon schema.

Best Regards,
George

Posted: Tue Jan 24, 2006 9:38 pm
by Andreas Kemkes
George:

My research last night brought me to the same conclusion. Unfortunately, it seems as if I'm out of luck with XHTML, as all the schemas that I could locate had a target namespace. Modularization seems to go into a different direction. I had considered the xmlns option, but it seemed verbose to me, as there may be many <p/> and other XHTML elements directly wrapped in <slidetext/>-like elements. The original idea was to just take the content of the <slidetext/> elements and place it into a <div/> for rendering. It would be nice, if all that could be validated accordingly. So right now, I'm just going to try prefixing properly, which unfortunately the renderer might need to strip. Thanks again for your help.

Regards,

Andreas

Posted: Wed Jan 25, 2006 11:00 am
by george
Hi Andreas,

From what you said I understand that you do not handle the content of slidetext with an XML aware application, for that it should not matter how the xhtml tags are really written (what prefix is used). If you want to just get the text out of there and if slidetext is in some namespace then you can declare the xhtml namespace as default namespace in slidetext and use a prefix for slidetext namespace:

Code: Select all


<s:slidetext xmlns:s="slidetextNamespacehttp://www.w3.org/1999/xhtml" xmlns="">
<p>...<p>
</s:slidetext>
Another way is to process the content of slidetext and extract it in no namespace, that is removing the namespace from the elements. That can be done with a very simple stylesheet like below:

Code: Select all


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="slideText">
<div>
<xsl:apply-templates mode="copyAndRemoveNS"/>
</div>
</xsl:template>

<xsl:template match="*" mode="copyAndRemoveNS" priority="2">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node() | @*" mode="copyAndRemoveNS"/>
</xsl:element>
</xsl:template>

<xsl:template match="node() | @*" mode="copyAndRemoveNS">
<xsl:copy>
<xsl:apply-templates select="node() | @*" mode="copyAndRemoveNS"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
for instance on the following document

Code: Select all


<slideText>
<p xmlns="http://www.w3.org/1999/xhtml">
<font size="10">.....</font>
</p>
</slideText>
it will give

Code: Select all


<?xml version="1.0" encoding="UTF-16"?>
<div>
<p>
<font size="10">.....</font>
</p>
</div>
Note that in the above slidetext is in no namepsace, if you have it in some namespace then your template/@match should be changed to match slidetext from that namespace, something like match="s:slidetext" xmlns:s="...".

Best Regards,
George