Reputation: 553
I would like to use html tags in the XML file so in my xsd file, I have allowed the html formatting by:
<xs:element name="description">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any namespace="http://www.w3.org/1999/xhtml"
processContents="lax"
minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
and in my XML file
<description>
<p xmlns="http://www.w3.org/1999/xhtml"> This course is an introduction to the information technologies required for secure, practical information systems for electronic commerce.
Topics will be chosen from areas such as document representation (XML, DTDs, XML Schema, XSLT, CSS),
</p> security (encryption, public key, symmetric key,
PKI, authentication); kinds of attack and vulnerabilities, electronic trading (spontaneous, deliberative, auctions), electronic document management
(metadata, search, digital libraries, management and processing), recent developments and maturation of the area,
such as web application frameworks, web services, the semantic web , mobile commerce </description>
However, when I change it to HTML file, it does not show anything! (no p)
I could not put html tags in xsl file because I wanted to divide contents within the description tag (one element of XSD). If there is any novel way I would accept it.
At first, even <p xmlns="http://www.w3.org/1999/XHTML">
did not work and I put
processContents="lax"
and it worked fine but still displaying one whole bunch of paragraph (so <p>
does not really work)
How can I make it work?
Upvotes: 0
Views: 14078
Reputation: 31641
Using the minimal example you give, the XML validates against the XSD snippet you provide (after adding an xs:schema
as a root element.)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="description">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any namespace="http://www.w3.org/1999/xhtml"
processContents="lax"
minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<description>
<p xmlns="http://www.w3.org/1999/xhtml"> This course is an introduction to the information technologies required for secure, practical information systems for electronic commerce.
Topics will be chosen from areas such as document representation (XML, DTDs, XML Schema, XSLT, CSS),
</p> security (encryption, public key, symmetric key,
PKI, authentication); kinds of attack and vulnerabilities, electronic trading (spontaneous, deliberative, auctions), electronic document management
(metadata, search, digital libraries, management and processing), recent developments and maturation of the area,
such as web application frameworks, web services, the semantic web , mobile commerce </description>
$ xmllint --noout --schema example.xsd test.xml
test.xml validates
So I'm not sure what your problem is.
One problem that comes to mind is you might not be using xhtml. The HTML you include in the description
element (or any HTML) must be valid xml (and hence xhtml, not the sloppy sgml-like html syntax), including making any xhtml named character entities (e.g.,
) available to the schema validator. Pretty much any html you find on the web will absolutely not be valid xml.
If you want to make the html available to XML processors and validation, use an XHTML 1.0 xsd or (more flexibly) mix and match modules available from XHTML 1.1 and its XSDs.
If this is too much trouble for you and you are ok with treating your HTML content as a blob of text, just include it as text content and modify your xsd schema to expect xs:string
or xs:normalizedString
as the content of the description
element.
Upvotes: 3
Reputation: 7722
Wrap the html content in CDATA
tags:
<![CDATA[<p>stuff</p>]]>
From msdn:
When an XML parser encounters the initial
<![CDATA[
, it reports the content that follows as characters without attempting to interpret them as element or entity markup. Character references do not work within CDATA sections. When it encounters the concluding]]>
, the parser stops reporting and returns to normal parsing.
Upvotes: 8