Mixing own XML with HTML5 havin eclipse to display code hints - html

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.

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?

How do I show actual HTML Code in textarea rather than rendered HTML?

I have a code that saves (html code) plus (some text) in mysql from textarea.
I then take the text from the mysql and display it under the textarea. The thing is if I save the code
<div style="color:red">Hello</div>
in mysql and then display it, I see Hello in red, but I want to see the actual
<div style="color:red">Hello</div>
to appear under the textarea. I hope you understand my problem.
so when you've grabbed the data from the database you want to actually display the html, rather than the page rendering the html?
if so just use the php function htmlentities();
You can use the xmp element, see What was the tag used for. It has been in HTML since the beginning and is supported by all browsers. Specifications frown upon it, but HTML5 CR still describes it and requires browsers to support it (though it also tells authors not to use it, but it cannot really prevent you).
Everything inside xmp is taken as such, no markup (tags or character references) is recognized there, except, for apparent reason, the end tag of the element itself, .
Otherwise xmp is rendered like pre.
When using “real XHTML”, i.e. XHTML served with an XML media type (which is rare), the special parsing rules do not apply, so xmp is treated like pre. But in “real XHTML”, you can use a CDATA section, which implies similar parsing rules. It has no special formatting, so you would probably want to wrap it inside a pre element:
<![CDATA[
This is a demo, tags will
appear literally.
<div style="color:red">Hello</div>
]]>
you can refer this ans : https://stackoverflow.com/a/16785992/3000179
If you want to do on browser level, you can follow the steps :
Replace the & character with &
Replace the < character with <
Replace the > character with >
Optionally surround your HTML sample with <pre> and/or <code>
tags.
Hope this helps.

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.

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

XSLT string with HTML entities - How can I get it to render as HTML?

I'm completely new to using XSL, so if there's any information that I'm neglecting to include, just let me know.
I have a string in my XSLT file that I can display like this:
<xsl:value-of select="#Description/>
and it shows up, rendered in a browser like:
<div>I can't do anything about the html entities existing in the text.</div> <div>This includes quotes, like "Hello World" and sometimes whitespaces. </div>
What can I do to get this string rendered as html, so that <div></div> results in newlines, " gives me ", and gives me a space?
I could elaborate on things I've already tried that haven't worked, but I don't know if that's relevant.
I think you want to set the following attribute as so:
<xsl:value-of select="#Description" disable-output-escaping="yes"/>
Why do you need to have entities output? To the browser is the same as   -- in both cases it will display a non-breaking space.
There is a feature in XSLT 2.0 called character-maps, that provide this functionality, if really needed. It is an XSLT best practice to try not to use DOE, unless absolutely necessary.
Also, DOE is not a mandatory feature of XSLT and some XSLT processors may not implement it. This means that an XSLT application that uses DOE is generally not portable across different XSLT processors.
The reason divs in HTML get an endline is completely different and related to the CSS boxmodel. Most browsers apply the style:
div {display:block;}
In lieu of the standard display:inline;. However, they only do that to divs in the XHTML namespace. You need to output divs to the XHTML namespace to faciliate that. Bind the XHTML namespace to the prefix xhtml at the top of your document like so:
<xsl:stylesheet xmnls:xhtml="http://www.w3.org/1999/xhtml" ... >
And then output the divs as <xhtml:div> ... </xhtml:div> most browsers would recognise the div to be in the XHTML namespace (http://www.w3.org/1999/xhtml) and apply the block style.