Click to See Complete Forum and Search --> : Using HTML tag in a XML node


louis_m_c
06-19-2008, 10:02 PM
I have a project which consist to put the result of a form isong tinymce (and other forms controls) into a xml file...

My xml file look like this:

Code :


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root [
<!ENTITY % HTML401 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!ENTITY % test PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
%test;
<!ELEMENT html (head, body)>
<!ENTITY % HTMLlat1 PUBLIC
"-//W3C//ENTITIES Latin 1 for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">
%HTMLlat1;
<!ENTITY % HTMLspecial PUBLIC
"-//W3C//ENTITIES Special for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent">
%HTMLspecial;
<!ENTITY % HTMLsymbol PUBLIC
"-//W3C//ENTITIES Symbols for XHTML//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent">
%HTMLsymbol;
]>
<Catalogue xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Services.xsd">
<Categories>
<NomCat>SERVICES</NomCat>
<TelContactCat>(000) 000-0000</TelContactCat>
<IndexCat id="C">S</IndexCat>
<DescriptionCat>Regroupe les services ayant trait au service &#xE0; la client&#xE8;le</DescriptionCat>
<Services>
<NomSrv>Gestion de l'int&#xE8;gration des applications</NomSrv>
<IndexSrv id="G">G</IndexSrv>
<IndexSrv id="I">I</IndexSrv>
<IndexSrv id="A">A</IndexSrv>
<NomContactSrv>Someone</NomContactSrv>
<TelContactSrv>(000) 000-0000</TelContactSrv>
<DescriptionSrv>...</DescriptionSrv>
<Englobage>...</Englobage>
<Cible>...</Cible>
<Financement>...</Financement>
<Attentes>...</Attentes>
<Contribution>...</Contribution>
<acces>...</acces>
<SiteWebSrv>http://</SiteWebSrv>
</Services>
<Categories>
</Catalogue>


I want the form users to be able to enter text formated a bit like in Word to let them use underscore, bold, links, etc... Tinymce return the result in HTML format...

So when I receive a service description (from the form), I want my xml file to be able to include HTML4.01 or XHTML1.0 tags into it's nodes.

ex:

<DescriptionSrv>this is <b>one</b> exemple</DescriptionSrv>


In my schema file, I've used xs:anyType instead of xs:string and I'm asking myself if this is the right thing to do...

I absolutly want to use a schema file because my application is better adapted to it than DTD, even if I import DTD so I don't have to convert special characters like "ç" into "&#xE7;" ...

Here is my schema:
Code :


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xs:complexType name="Catalogue">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Categories"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Catalogue" type="Catalogue"/>
<xs:complexType name="Categories">
<xs:sequence>
<xs:element ref="NomCat"/>
<xs:element ref="ContactCat"/>
<xs:element ref="TelContactCat"/>
<xs:sequence maxOccurs="26">
<xs:element ref="IndexCat"/>
</xs:sequence>
<xs:element ref="DescriptionCat"/>
<xs:element ref="SiteWebCat" minOccurs="0"/>
<xs:element ref="Services" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Categories" type="Categories" nillable="false"/>
<xs:element name="NomCat" nillable="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="ContactCat" nillable="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="TelContactCat" type="phoneType" nillable="false"/>
<xs:element name="DescriptionCat" type="xs:anyType" nillable="false"/>
<xs:complexType name="IndexCat" mixed="true">
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="A"/>
<xs:enumeration value="B"/>
<xs:enumeration value="C"/>
<xs:enumeration value="D"/>
<xs:enumeration value="E"/>
<xs:enumeration value="F"/>
<xs:enumeration value="G"/>
<xs:enumeration value="H"/>
<xs:enumeration value="I"/>
<xs:enumeration value="J"/>
<xs:enumeration value="K"/>
<xs:enumeration value="L"/>
<xs:enumeration value="M"/>
<xs:enumeration value="N"/>
<xs:enumeration value="O"/>
<xs:enumeration value="P"/>
<xs:enumeration value="Q"/>
<xs:enumeration value="R"/>
<xs:enumeration value="S"/>
<xs:enumeration value="T"/>
<xs:enumeration value="U"/>
<xs:enumeration value="V"/>
<xs:enumeration value="W"/>
<xs:enumeration value="X"/>
<xs:enumeration value="Y"/>
<xs:enumeration value="Z"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:element name="IndexCat" type="IndexCat" nillable="false"/>
<xs:element name="SiteWebCat" type="xs:anyURI" default="http://" nillable="false"/>
<xs:complexType name="Services">
<xs:sequence>
<xs:element ref="NomSrv"/>
<xs:sequence maxOccurs="26">
<xs:element ref="IndexSrv"/>
</xs:sequence>
<xs:element ref="NomContactSrv"/>
<xs:element ref="TelContactSrv"/>
<xs:element ref="DescriptionSrv"/>
<xs:element ref="Englobage"/>
<xs:element ref="Cible"/>
<xs:element ref="Financement"/>
<xs:element ref="Attentes"/>
<xs:element ref="Contribution"/>
<xs:element ref="acces"/>
<xs:element ref="SiteWebSrv" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:element name="Services" type="Services" nillable="false"/>
<xs:element name="NomSrv" nillable="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="255"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DescriptionSrv" type="xs:anyType" nillable="false"/>
<xs:complexType name="IndexSrv" mixed="true">
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="A"/>
<xs:enumeration value="B"/>
<xs:enumeration value="C"/>
<xs:enumeration value="D"/>
<xs:enumeration value="E"/>
<xs:enumeration value="F"/>
<xs:enumeration value="G"/>
<xs:enumeration value="H"/>
<xs:enumeration value="I"/>
<xs:enumeration value="J"/>
<xs:enumeration value="K"/>
<xs:enumeration value="L"/>
<xs:enumeration value="M"/>
<xs:enumeration value="N"/>
<xs:enumeration value="O"/>
<xs:enumeration value="P"/>
<xs:enumeration value="Q"/>
<xs:enumeration value="R"/>
<xs:enumeration value="S"/>
<xs:enumeration value="T"/>
<xs:enumeration value="U"/>
<xs:enumeration value="V"/>
<xs:enumeration value="W"/>
<xs:enumeration value="X"/>
<xs:enumeration value="Y"/>
<xs:enumeration value="Z"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:element name="IndexSrv" type="IndexSrv" nillable="false"/>
<xs:element name="NomContactSrv" nillable="false">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="TelContactSrv" type="phoneType" nillable="false"/>
<xs:element name="SiteWebSrv" type="xs:anyURI" default="http://" nillable="false"/>
<xs:element name="acces" type="xs:anyType" nillable="false"/>
<xs:element name="Financement" type="xs:anyType" nillable="false"/>
<xs:element name="Englobage" type="xs:anyType" nillable="false"/>
<xs:element name="Contribution" type="xs:anyType" nillable="false"/>
<xs:element name="Cible" type="xs:anyType" nillable="false"/>
<xs:element name="Attentes" type="xs:anyType" nillable="false"/>
<xs:simpleType name="phoneType">
<xs:restriction base="xs:string">
<xs:pattern value="\([0-9]{3}\) [0-9]{3}-[0-9]{4}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>



Thanks in advance!

sstalder
06-20-2008, 09:20 AM
http://www.w3schools.com/XML/xml_cdata.asp

louis_m_c
06-20-2008, 05:46 PM
this is for DTD not for schemas...

rpgfan3233
06-20-2008, 06:06 PM
Well, if you used a CDATA section, you shouldn't have any problems...

<example>
<blah>
<![CDATA[
<p id="Result">Blah</p>
]]>
</example>

The contents of a CDATA section can be any Unicode character, so even if you had ç instead of &#xE9;, it should still be valid in XML Schema. For the DTD, if you choose to use it, remember to use something like <!ELEMENT blah (#PCDATA)>

I hope this helps!

louis_m_c
06-20-2008, 09:16 PM
Didn't I mentioned I don't want to use DTD for this for some reasons??

The same thing must be possible with Schema! And that's what I want.

DTD won't help me for this one. Not enough data validation, etc.

rpgfan3233
06-20-2008, 10:16 PM
You already have the answer. Here's an example:

test.xsd -
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns="urn:rpgfan3233" targetNamespace="urn:rpgfan3233" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

<xs:complexType name="rpgfan3233.blah.type" mixed="true">
<xs:sequence/>
</xs:complexType>

<xs:complexType name="rpgfan3233.example.type">
<xs:sequence>
<xs:element name="blah" type="rpgfan3233.blah.type" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:element name="example" type="rpgfan3233.example.type"/>
</xs:schema>

test.xml -
<?xml version="1.0" encoding="utf-8"?>
<example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:rpgfan3233"
xsi:schemaLocation="urn:rpgfan3233 test.xsd">

<blah>
<![CDATA[
<p>Boo!</p>
]]>
</blah>
</example>

If you have an element that contains CDATA, add mixed="true" to the type declaration in the XML schema document. Note that CDATA is either an explicitly declared CDATA block or just normal text. If I changed <p>Boo!</p> to &lt;p&gt;Boo!&lt;/p&gt; then it would also be the same thing.

louis_m_c
06-20-2008, 10:28 PM
I don't want to put DTD's code

<![CDATA[
<p>Boo!</p>
]]>


in my nodes just to by-pass the problem either... I don't want to have to parse each nodes every times to remove the <![CDATA[ and ]]> strings when I need to display them through a xslt file or javascript/vbscripts/etc...

I want something purely associated to Schema for this. I can't imagine this does not exist, It would be a horrible omission from w3c which I doubt they did omit.

I don't wan to argue about the rightfulness of DTD over Schema, my work need to be done exclusively with Schema. If needed I'll post to someone at w3c or O'Reilly directly. Please no more DTD solutions. Sometimes one cannot choose the way things need to be done, in some industries, they use standards and if they don't want DTD it's not my business to argue...

rpgfan3233
06-20-2008, 10:55 PM
<DescriptionSrv>this is <xhtml:b>one</xhtml:b> exemple</DescriptionSrv>

Notice the namespace prefix. In case you don't know, you need to declare it as xmlns:xhtml in your root element, and you should be okay.

The necessary schema for DescriptionSrv:
<xs:complexType name="DescriptionSrv.type">
<xs:sequence>

<!-- allow any element from the XHTML namespace -->
<!-- note that lax processing is used due to the lack of interest in finding
and importing the schema -->
<xs:any namespace="http://www.w3.org/1999/xhtml" processContents="lax" minOccurs="0"/>

</xs:sequence>
</xs:complexType>

<xs:element name="DescriptionSrv" type="DescriptionSrv.type" mixed="true"/>

Does that work for you? For the record, I'm assuming you want to actually use the XHTML rather than just displaying the XHTML code by posting that. Otherwise, encode your tags or use CDATA sections (they're NOT a part of DTD).

louis_m_c
06-20-2008, 11:26 PM
but that mean parsing the code inside of the nodes when displaying them and writing them right? remember that I receive my datas from tinymce as raw html data...

Or i'm wrong??