Your HTML title

Display HTML in XSL Style Sheet

This article describes how to work with the XSL style sheets to use the HTML tags that are inside XML data.

Original product version: XSL style sheets
Original KB number: 264665

Summary

When XML data contains HTML tags, those tags are considered as plain data by default, and are not parsed as HTML. The output displays as text without HTML effects. This article explains how to work with the XSL style sheets to use the HTML tags that are inside XML data.

More information

In the xsl:value-of element, use the XSL disable-output-escaping property, and then set it to yes. By default disable-output-escaping is set to no. This property was added with the May 2000 version of the XML parser.

You may install the latest version of the MS XML parser from MSXML Roadmap.

The following XML/XSL example demonstrates how to work with the XSL style sheets to use the HTML tags that are inside XML data:

The HTML data in the first line can be written with special character sequences and CDATA section, as demonstrated in the following examples:

Читайте также:  Php throw existing exception

Characters such as < and >are reserved characters in XML, and are not interpreted if they are placed in an XML file. Substitute these characters with case-sensitive character sequences. For more information on Microsoft’s work with XML, see MSXML SDK Overview.

The following is the corresponding TestHTML.xsl file that demonstrates how to work with the XSL style sheets to use the HTML tags that are inside XML data:

==========================================================================      
Expected action HTML display
==========================================================================

References

Источник

How to Insert HTML Content in Xml Document

Is it possible to insert HTML content in XML document?

You can include HTML content. One possibility is encoding it in BASE64 as you have mentioned.

Another might be using CDATA tags.

 





Your HTML's body
]]>

CDATA’s opening character sequence:

CDATA’s closing character sequence: ]]>

HTML tags within XML

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:

 



processContents="lax"
minOccurs="0"
maxOccurs="unbounded" />

test.xml:

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

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., ) 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.

Use HTML tags in XML file and display/recognize them later as HTML

It is still not clear what is your problem and what is your goal.

Let me try to do some attempt to help you.

First thing — you have data:

That data portion has html encoded characters. The point is to never mix data with real html or xml.

$this->topics[$page] = $thema->description;

your value still contain html encoded characters:

$this->topics[$page] === `Die Zweckbestimmung ist ein eleme Konsequenzen.`

Which is probably kind wrong from your point of view. But to me I don’t see any problem yet at this moment.

Lets simplify and focus only on this part:

That one of things which are not clear in your data xml there is no field with name questiontext . So lets assume that is topic->question->comment .

How can I include HTML in an XML document?

You can wrap the HTML in CDATA tags (character data) to indicate raw, uninterpreted/unparsed text.

The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure. . In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup.

Add HTML Codes to XML file using PHP

You can use the PHP function createCDATASection to add CDATA to your xml file:

$newGame -> appendChild($scores -> createElement("Header", $_POST['header']));
$h = $scores -> createElement("Header"); //Create a empty tag
$h -> appendChild($scores ->createCDATASection ($_POST['header'])); //Add a CDATA element to it
$newGame -> appendChild($h); //Then append it to the game tag

With the comments, it should be quite straight-forward.

XSLT Insert html content

 




some link


some link1


some link2

This stylesheet will do what you want to do:

Источник

Including HTML data in an xml document

When developing an xml-based application, you may come across the need to include HTML data in xml nodes. The problem is that unless this data is escaped in some way, it is interpreted as xml and will cause a malformed structure. The easiest way I’ve found so far to use a CDATA attribute to escape the code automatically. Then, when you are creating an xsl fragment to edit or display the data, use

  Example of xml which contains HTML data: 




09/01/2007


This is an excerpt that contains some HTML data. testing URL's in cdata section
]]>

This is the rest of the article and contains some HTML code
Author name

09/01/2007


Short excerpt here.testing URL's in cdata section
]]>



another author


Example of XSL fragment which displays the data:

Leave a Reply Cancel reply

You must be logged in to post a comment.

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. OkNoPrivacy policy

Источник

Оцените статью