简体   繁体   English

将自己的XML与HTML5 havin eclipse混合以显示代码提示

[英]Mixing own XML with HTML5 havin eclipse to display code hints

I am writing my own templating engine mainly for web applications. 我正在编写自己的模板引擎,主要用于Web应用程序。

It is actually mix of my own XML tags and HTML. 它实际上是我自己的XML标签和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. 一点解释:那些带有“ lp”前缀的标签属于我的模板引擎,并且是它的“处理指令”。 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. lp:view是一个根节点,然后有一个lp:list节点,接收到一些数据源将产生一个列表:首先它将包含lp:list_header的内容,然后重复正确的时间lp:list_item的内容(替换$按实际数据显示title $,但这并不重要),那么它将添加lp:list_footer节点的内容。 As you can see, for this reason I have html tag "table" splitting across my tags. 如您所见,由于这个原因,我将html标签“ table”拆分为多个标签。

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? 我在这里遇到了两个主要问题:1. Eclipse抱怨“表”未正确关闭-我希望Eclipse停止抱怨,将此标记视为文本,或者-也许您可以提出一些建议? 2. Eclipse will not show any code hint if I am inside any of html tags. 2.如果我在任何html标记内,Eclipse将不会显示任何代码提示。 (code hint: attributes that maybe used by this tag like "class" or "id" etc) (代码提示:此标记可能使用的属性,例如“ class”或“ id”等)

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! 我知道我在问一个怪异的怪胎问题,但也许这里有一些XSD专家可以指导我:Eclipse应该将我的xml模板文件视为以下内容:1.前缀为“ lp”的标签是上帝! 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. 2.所有其他标签(尖括号之间的所有内容)均为HTML标签。 Eclipse should display code hint for them, but should anything be "incorrect" (like in my sample: no closing /table tag) -- Eclipse should not complain. Eclipse应该为它们显示代码提示,但是任何东西都应该是“不正确的”(例如在我的示例中:没有关闭/ table标记)- Eclipse不应抱怨。

I hope this is possible. 我希望这是可能的。

thanks! 谢谢!

You would have to wrap your HTML in CDATA blocks. 您必须将HTML包装在CDATA块中。 This will make the XML parser consider the contents (the unclosed <table> ) to be plain text, and not a broken tag. 这将使XML解析器将内容(未关闭的<table> )视为纯文本,而不是损坏的标记。

    <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: 要停止Eclipse抱怨未关闭的标签,您应该将内容包装在<![CDATA[..]]节中,如下所示:

<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. 它们将被视为文本,并且Eclipse不会抱怨,但是在那种情况下,您将在CDATA部分中丢失任何Eclipse完成。

To get completion working for HTML tags, I think you can try adding a default namespace for XHTML to your root tag, like so: 为了使HTML标记完成工作,我认为您可以尝试将XHTML的默认命名空间添加到根标记中,如下所示:

<?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> . 编辑:我认为第二部分将无法工作,因为XHTML架构定义了根元素应为<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. 我只是在Eclipse中尝试过,只有当我第一次在文档中的某个位置插入<html>标记时,HTML标记的完成功能才开始起作用。 Maybe some other people can weigh in. 也许其他人可以加入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM