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

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?

Related

How to use XSLT to display CDATA content in TD tags

I have some formatted text in XML within CDATA tag. XSLT puts this data in table of columns Attribute Name & Attribute Value. Attribute Value has CDATA tag but when its added to table it does not display formatted text. Instead it displays "<p> <strong> <span style="color:#FF8C00;">Test data for this requirementlt;/span> </strong> </p>"
It should display like below
Can someone help me with solution?
The CDATA tag tells the XML parser not to parse the content. So if you want it parsed, you need to extract it from the CDATA section and submit it to a second parsing run. With a modern XSLT processor you can do this using a function call such as parse-xml(), but with older processors you will need to call an extension function.
If you want to simply copy the content of the CDATA section to the serialized output, without modification and without escaping the markup, then you might be able to use <xsl:value-of select="..." disable-output-escaping="yes"/>. However, this only works if the transformation output is being sent to a serializer: which isn't the case, for example, with some browsers.

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.

xml cdata not allowing 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.

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