将自己的XML与HTML5混合使用eclipse来显示代码提示
我正在编写自己的模板引擎,主要用于 Web 应用程序。
它实际上是我自己的 XML 标签和 HTML 的混合。
这是示例:
<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>
一点解释: 这些以“lp”为前缀的标签属于我的模板引擎,是它的“处理指令”。 lp:view 是一个根节点,然后有一个 lp:list 节点,它接收到一些数据源后会产生一个列表:首先它将包含 lp:list_header 的内容,然后重复适当的次数 lp:list_item 的内容(替换 $ title$ 为实际数据,但这在这里无关紧要),然后它将添加 lp:list_footer 节点的内容。正如您所看到的,由于这个原因,我将 html 标签“table”分成了我的标签。
我在这里遇到了两个主要问题: 1. Eclipse 抱怨“表”未正确关闭 - 我希望 Eclipse 停止抱怨,将此标签视为文本,或者 - 也许您可以建议一些东西? 2. 如果我位于任何 html 标签内,Eclipse 将不会显示任何代码提示。 (代码提示:此标签可能使用的属性,如“class”或“id”等)
我知道我在问一个奇怪的问题,但也许这里有一些 XSD 专家可以指导我: Eclipse 应按如下方式处理我的 xml 模板文件: 1.前缀为“lp”的标签都是神!它们优先于其他任何事物。仅应显示来自该标记的错误(缺少必需的属性、缺少必需的子元素等)。 2. 所有其他标签(尖括号之间的任何内容)都是 HTML 标签。 Eclipse 应该为它们显示代码提示,但是如果有任何内容“不正确”(就像在我的示例中:没有结束 /table 标记)——Eclipse 不应该抱怨。
我希望这是可能的。
谢谢!
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>$titlelt;/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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将 HTML 包装在
CDATA
块中。这将使 XML 解析器将内容(未封闭的)视为纯文本,而不是损坏的标签。
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.这只是部分答案,但我仍然会将其作为答案,因为它太长,无法输入评论。
要阻止 Eclipse 抱怨未封闭的标签,您应该将内容包装在
部分中,如下所示:
它们将被视为文本,Eclipse 不会抱怨,但在这种情况下,您将丢失 CDATA 部分内的任何 Eclipse 完成。
要完成 HTML 标签的工作,我认为您可以尝试将 XHTML 的默认命名空间添加到根标签中,如下所示:
编辑:我认为第二部分不起作用,因为 XHTML 架构定义根元素应该是
。我刚刚在 Eclipse 中尝试过,只有当我第一次在文档中的某处插入
标记时,HTML 标记的补全才开始工作。也许其他一些人可以权衡一下。
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: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:
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.