xml cdata not allowing html - html

So from what I understand of the CDATA tags on an XML document, it's meant to allow HTML tags inside it to function as they normally would.
I am working with a website template here that uses XML files, and while editing one of the documents to add a href or image to it, I rather get a string. Here's the code, if you can help me that would be greatly appreciated.
I have tried modifying the code to use the < / > that it seems to want to suggest in the output text, but that doesn't help either. If anybody can explain or link me to relevant information, or both, it would be amazing =)
<?xml version="1.0"?>
<xmldata section="Address">
<content>
<image src="resources/images/streetmap1.png" />
<bodytext><![CDATA[Shop 6, 106 Foster Street
Dandenong, 3175
Street Map:
<image src="resources/images/streetmap1.png" />
]]></bodytext>
</content>
</xmldata>
EDIT - Supplying accompanying .js file.
http://pastebin.com/Td2EYiKH

So from what I understand of the CDATA tags on an XML document, it's meant to allow HTML tags inside it to function as they normally would.
No. It is so that characters with special meaning in XML (such as <) can be included as data without escaping.
Here's the code
You need to look at the code that transforms the XML data into the HTML content. You haven't shared that with us.
<image src="resources/images/streetmap1.png" />
The HTML element is img not image and it should have an alt attribute.

Related

Trying to include Text and HTML inside XML schema but receiving failure

For a personal project I need to get information from an excel-sheet into xml-data (xml-schema needed) but if I try to validate it this error shows: "Non-HTML Content-Type: text/xml ."
The excel sheet includes information such as basic text, which is quite simple to transport into xml, but also has long html inside its cells which later should be used as content of a wordpress site/post. So this hmtl begins with visualcomposer elemnts like "[vc_row][vc_column][vc_column_text]" and further more contains very standard html elements like paragraphs or tables. All html is wrapped inside .
So I wonder if this could be the source of my problem as, with my very slim coding and debugging knowledge, this came in my mind first.
Some extra information:
the xml-schema is edited with Dreamweaver CC 2015 which also does the validation
the xml-file is characterized, with: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<materialData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Data inside the xml is structured like: <matData><ID>3001</ID><author>1</author> ... </matData>
I suspect what you need is to correctly enclose the values that will include html in cdata tags so there not seen as xml.
<exampleOfACDATA>
<![CDATA[
Since this is a CDATA section
I can use all sorts of reserved characters
like > < " and &
or write things like
<foo></bar>
but my document is still well formed!
]]>
</exampleOfACDATA>
see further details here
What does <![CDATA[]]> in XML mean?

xml (TEI P5) visualisation method

I've encoded a book with xml, according to TEI P5 guidelines, and I'm trying to visualize it in an html page. The real aim is to visualize the encoded text with all its formatting tags of TEI P5 guidelines (text formatting, inner references, etc.). So, the big question is how we do this right?
{For the record: I've tried (and still trying) to "throw" the whole xml text in the html body, and edit the visualization in a parallel css stylesheet, which I link to the html <style>. But, something doesn't seem quite right...}
Any thought?? Any example??
Here an xml sample:
<?xml version="1.0" ?>
<TEI version="5.0" xmlns="http://www.tei-c.org/ns/1.0">
<!--here exists the teiHeader-->
<text>
<front>
<div type="preface">
<head rend="align(center)">
<hi rend="bold">title</hi></head>
<p>Here is the prologue.Here is the prologue.</p>
<p>And second para of prologue.</p>
<p><ref target="#memories">Here is first reference to an xml:id, which have created to the teiHeader.</ref> Some more prologue. <ref target="#modernNovel">Here is the second reference to an xml:id, which have created to the teiHeader.</ref> and more prologue.</p>
<closer>
<salute rend="align(right)">Dear readers</salute>
<signed rend="align(right)">signature</signed>
</closer>
</div>
</front>
<body>
<ab type="title">
<title rend="align(center)" type="main">
TITLE
</title>
<lb/>
<title rend="align(center)" type="desc">
Secondary title
</title>
</ab>
<div n="1" type="chapter">
<head rend="align(center)">
<hi rend="bold">Chapter 1 <lb/>name of the chapter.</hi>
</head>
<p>Here is the real text, and text, and more text. Again the text, and text, and more text.Again the text, and text, and more text.An finally the name <placeName xml:id="London"> <hi rend="bold">London</hi></placeName>, appears here.</p>
<p>Here is the real text, and text, and more text. Again the text, and text, and more text.Again the text, and text, and more text.An the name <ref target="London"> <hi rend="bold">London</hi></ref>, repeat itself.</p>
</div>
</body>
Your use of the #rend attribute suggests that you're trying to use it to supply CSS styling properties. If that's so, you might find it easier to use the #style or #rendition attributes instead, since these are intended for that purpose. Remember however that all three of these attributes are intended to describe the rendition of the source. The TEI doesn't (as yet) provide ways of specifying how particular components of a document should be processed: this was considered out of scope for the original project. However, there is work being done in the area of defining a "processing model" for TEI elements, which should appear in the Guidelines soon. See for example the TEI Simple project.
Yes! I'd strongly recommend writing XSLT to transform your XML into HTML, as this will give you the most control over how your TEI elements are to be rendered in a web browser. It also makes it possible for you to generate multiple different options for structuring and styling your pages.
For example, if you want to extract a list of all the character names you have tagged in the TEI, and count the number of times they appear in each chapter, and do other kinds of analytical processing, XSLT is the tool you want. And you can use it to generate a full reading view of your text.

HTML within XML is not displayed properly in the output after conversion using XSLT

I've an XML file generated as an output of a Java program. This contains some text in the form of html in which the tags are written with < and > instead of < and > respectively. I want to convert this xml to html where in the inner html is also processed. For example:
My xml snippet:
<company>
<companyEnhancement>
Rank: -1</br> Other Links</br>http://www.gehealthcare.com/</br>
</companyEnhancement>
</company>
And, my xslt stylesheet has this part to parse it:
<td>
<xsl:value-of select="companyEnhancement"/>
</td>
But the html output on the browser, has this data as it is within a table cell:
Rank: -1 </br> Other Links</br>http://www.gehealthcare.com/</br>
I read through the links here, but I am not able to understand what exactly I should do in the stylesheet.
Please help me out. I am very new to xslt, so please excuse if it is a silly question.
Thanks
You say you have HTML in there but </br> is not HTML syntax, that would be <br> or perhaps for XHTML <br />.
If you really have escaped HTML and want to output that then you can try
<xsl:value-of select="companyEnhancement" disable-output-escaping="yes"/>
but that is only going to help if your XSLT processor serializes the result tree. Firefox for instance does not do that and does not support disable-output-escaping.

Mixing own XML with HTML5 havin eclipse to display code hints

I am writing my own templating engine mainly for web applications.
It is actually mix of my own XML tags and HTML.
Here is the sample:
<lp:view xmlns:lp="http://sminit.com/view" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://sminit.com/view view.xsd ">
<lp:list name="my_items">
<lp:list_header>
<table>
</lp:list_header>
<lp:list_item>
<tr><td>$title$</td></tr>
</lp:list_item>
<lp:list_footer>
</table>
</lp:list_footer>
</lp:list>
</lp:view>
A little explanation:
Those tags prefixed with "lp" belong to my templating engine and are kind of "processing instructions" for it. The lp:view is a root node, then there is a lp:list node which having received some data source will produce a list: first it will include content of lp:list_header, then repeat proper times content of lp:list_item (replacing $title$ by actual data, but this does not matter here), then it will add content of lp:list_footer node. As you can see, for this reason I have html tag "table" splitting across my tags.
I have met two major problems here:
1. Eclipse complains that "table" is not properly closed -- I want Eclipse to stop complaining, treat this tag as a text or -- maybe you can suggest something?
2. Eclipse will not show any code hint if I am inside any of html tags. (code hint: attributes that maybe used by this tag like "class" or "id" etc)
I understand that I'm asking a weird freak question, but maybe there are some XSD gurus here who can direct me:
Eclipse should treat my xml template file as the following:
1. the tags prefixed "lp" are gods! They have precedence over anything other. Only errors from that tags (missing required attributes, missing required child elements etc) should be displayed.
2. All the other tags (any stuff in between angle brackets) are HTML tags. Eclipse should display code hint for them, but should anything be "incorrect" (like in my sample: no closing /table tag) -- Eclipse should not complain.
I hope this is possible.
thanks!
You would have to wrap your HTML in CDATA blocks. This will make the XML parser consider the contents (the unclosed <table>) to be plain text, and not a broken tag.
<lp:list_header><![CDATA[
<table>
]]></lp:list_header>
This is just a partial answer, but I'll still put it as an answer because it's too long to type into a comment.
To stop Eclipse complaining about unclosed tags, you should wrap the content in a <![CDATA[..]] section like so:
<lp:view xmlns:lp="http://sminit.com/view" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sminit.com/view view.xsd ">
<lp:list name="my_items">
<lp:list_header>
<![CDATA[ <table> ]]>
</lp:list_header>
<lp:list_item>
<tr><td>$title$</td></tr>
</lp:list_item>
<lp:list_footer>
<![CDATA[ </table> ]]>
</lp:list_footer>
</lp:list>
They will be treated as text and Eclipse will not complain, but in that case you will lose any Eclipse completion inside the CDATA section.
To get completion working for HTML tags, I think you can try adding a default namespace for XHTML to your root tag, like so:
<?xml version="1.0" ?>
<lp:view xmlns="http://www.w3.org/1999/xhtml" xmlns:lp="http://sminit.com/view" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://sminit.com/view view.xsd ">
<lp:list name="my_items">
<lp:list_header>
<![CDATA[ <table> ]]>
</lp:list_header>
<lp:list_item>
<tr><td>$title$</td></tr>
</lp:list_item>
<lp:list_footer>
<![CDATA[ </table> ]]>
</lp:list_footer>
</lp:list>
EDIT: I think the second part won't work though, because the XHTML schema defines that the root element should be <html>. I just tried in Eclipse and completion for HTML tags only starts working when I first insert an <html> tag somewhere in the document. Maybe some other people can weigh in.

Is it possible to insert HTML content in XML document?

I need to insert HTML content into an XML document, is this possible or should HTML content be, for example, encoded in BASE64 or with something else like that?
You can include HTML content. One possibility is encoding it in BASE64 as you have mentioned.
Another might be using CDATA tags.
Example using CDATA:
<xml>
<title>Your HTML title</title>
<htmlData><![CDATA[<html>
<head>
<script/>
</head>
<body>
Your HTML's body
</body>
</html>
]]>
</htmlData>
</xml>
Please note:
CDATA's opening character sequence: <![CDATA[
CDATA's closing character sequence: ]]>
so long as your html content doesn't need to contain a CDATA element, you can contain the HTML in a CDATA element, otherwise you'll have to escape the XML entities.
<element><![CDATA[<p>your html here</p>]]></element>
VS
<element><p>your html here</p></element>
The purpose of BASE64 encoding is to take binary data and be able to persist that to a string. That benefit comes at a cost, an increase in the size of the result (I think it's a 4 to 3 ratio). There are two solutions. If you know the data will be well formed XML, include it directly. The other, an better option, is to include the HTML in a CDATA section within an element within the XML.
Please see this.
Text inside a CDATA section will be ignored by the parser.
http://www.w3schools.com/xml/dom_cdatasection.asp
This is will help you to understand the basics about XML
Just put the html tags with there content and add the xmlns attribute with quotes after the equals and in between the quotes is http://www.w3.org/1999/xhtml