SUBJECT: XML schema together with XHTML

D

dantohester

Hi there,

I have the following situation:
I want to create an XML document that contains 2 parts:
a) a XHTML part (it can be either version 1.0 or 1.1 )
b) a non XHTML part that contains some information about the first
part - like the location of that content or some other info on
different constituents of the first part

The elements of the second part are defined by an XML schema.

My question is how to do this in an elegant manner?
Should I import somehow (I have no idea how) the XHTML schema on the
part 2 schema? Or should I deal only on the instance XML file with
this issue (if yes - how)?

Thanks a lot for the help.

Daniel
 
M

Martin Honnen

I have the following situation:
I want to create an XML document that contains 2 parts:
a) a XHTML part (it can be either version 1.0 or 1.1 )
b) a non XHTML part that contains some information about the first
part - like the location of that content or some other info on
different constituents of the first part

The elements of the second part are defined by an XML schema.

My question is how to do this in an elegant manner?
Should I import somehow (I have no idea how) the XHTML schema on the
part 2 schema? Or should I deal only on the instance XML file with
this issue (if yes - how)?

You can author the schema for the elements you want to define yourself
and then, where XHTML elements are allowed, you use xs:any together with
the XHTML namespace http://www.w3.org/1999/xhtml. On the xs:any element
you use the attribute processContents="lax", that way the processor will
validate if a schema for that namespace is known or skip validation if
no schema is known.
As for importing an XHTML schema, the W3C has made various efforts at
doing this, one is <http://www.w3.org/TR/xhtml1-schema/>, it is only a
note however, not a normative schema. Importing a schema is simply done
with e.g.
<xs:import namespac="http://www.w3.org/1999/xhtml"/>
with an optional URL provided for the schema location.
 
D

dantohester

Martin,
Thanks for your pointer - it is very useful.
I am still getting an error on the validation. Maybe I am doing
something wrong.


I did this:

###schema
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.myTarget.com"
xmlns="http://www.myTarget.com"
elementFormDefault="qualified">

<xsd:element name="LDOC">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="XHTML" minOccurs="1" maxOccurs="1"/>
<xsd:element ref="META" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="XHTML" type="XHTMLType"/>
<xsd:complexType name="XHTMLType">
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xsd:anyAttribute namespace="http://www.w3.org/1999/
xhtml" processContents="lax"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

####### xml file

<?xml version="1.0" encoding="UTF-8"?>
<lxx:LCCDOC xmlns:lxx="http://www.myTarget.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.myTarget.com
file:LDocument_V0.xsd">

<lxx:XHTML>
<html></html> <!-- ERROR -->
</lxx:XHTML>

<lxx:META>
 
D

dantohester

My BAD,
I was making a mistake. Bellow is the good example.
A problem still arises: the solution works if my XHTML part has an
XHTM schema header. What if that XHTML is "coordinated" by a DTD? How
can I still incorporate that part in my XML file?

I do appreciate your help - Thank you!

Daniel

the good XML schema:
<xsd:element name="XHTML">
<xsd:complexType>
<xsd:sequence>
<xsd:any minOccurs="0" namespace="http://www.w3.org/
1999/xhtml" processContents="lax"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top