0

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?

6
  • 1
    what do you mean by "when I change it to HTML file, it does not show anything"? What are the two "it" pronouns referring to? What are you using to "show"? Commented Sep 19, 2012 at 2:27
  • What do you mean by "when I change it to HTML file" ? Commented Sep 19, 2012 at 2:39
  • The provided XML file/text isn't well-formed XML document. Commented Sep 19, 2012 at 2:41
  • Actually the XML is fine. Everything seems to be fine, except I'm not sure what the OP is after. Commented Sep 19, 2012 at 2:46
  • HTML file change means using XSLT to convert XML to HTML. Commented Sep 19, 2012 at 2:54

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

but the problem with CDATA is that it just returns <p> without doing its function (having it as different paragraph)
3

Using the minimal example you give, the XML validates against the XSD snippet you provide (after adding an xs:schema as a root element.)

example.xsd:

<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>

test.xml:

<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>

Validation:

$ 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., &nbsp;) 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.

4 Comments

Francis, thanks for the detailed answer, yes, my xml also validates but the problem is that if I put <p> tag, it should separate the paragraph into two paragraphs but it is not doing its right function. In this case, what is the problem? (the xml and xsd provided is just a portion of my xsd and xml)
You have only one <p></p> pair, so you have only one paragraph, not two. In any case, if this question pertains to your xslt output not being what you expect, you need to make some drastic changes to your question so we can understand you. (See my other comment below your question.)
I have solved the question ( I searched on the web and there was an excellent solution to the problem that I have faced)
Then add the solution you used as an answer here, and fix your question. Just marking my (irrelevant) answer as correct doesn't help anyone else!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.