扩展 XHTML [英] Extending XHTML

查看:9
本文介绍了扩展 XHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用属性来定义表单验证行为的 jQuery 插件(是的,我知道已经有一个验证插件;这和我将要使用的东西一样是一个学习练习).理想情况下,我想要这样的东西:

I'm playing around with writing a jQuery plugin that uses an attribute to define form validation behavior (yes, I'm aware there's already a validation plugin; this is as much a learning exercise as something I'll be using). Ideally, I'd like to have something like this:

示例 1 - 输入:

<input id="name" type="text" v:onvalidate="return this.value.length > 0;" />

示例 2 - 包装器:

Example 2 - wrapper:

<div v:onvalidate="return $(this).find('[value]').length > 0;">
   <input id="field1" type="text" />
   <input id="field2" type="text" />
   <input id="field3" type="text" />
</div>

示例 3 - 预定义:

Example 3 - predefined:

<input id="name" type="text" v:validation="not empty" />

这里的目标是让我的 jQuery 代码找出需要验证的元素(这已经完成),并且标记仍然是有效的 XHTML,这是我遇到的问题.我相当确定这将需要 DTD 和 XML Schema 的组合,但我不太确定如何执行.

The goal here is to allow my jQuery code to figure out which elements need to be validated (this is already done) and still have the markup be valid XHTML, which is what I'm having a problem with. I'm fairly sure this will require a combination of both DTD and XML Schema, but I'm not really quite sure how exactly to execute.

基于这篇文章,我创建了以下 DTD:

Based on this article, I've created the following DTD:

<!ENTITY % XHTML1-formvalidation1
    PUBLIC  "-//W3C//DTD XHTML 1.1 +FormValidation 1.0//EN"
            "http://new.dandoes.net/DTD/FormValidation1.dtd" >
%XHTML1-formvalidation1;

<!ENTITY % Inlspecial.extra 
  "%div.qname; " >

<!ENTITY % xhmtl-model.mod
    SYSTEM "formvalidation-model-1.mod" >  
<!ENTITY % xhtml11.dtd
    PUBLIC  "-//W3C//DTD XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
%xhtml11.dtd;

这里是formvalidation-model-1":

And here is "formvalidation-model-1":

<!ATTLIST %div.qname;
    %onvalidation   CDATA   #IMPLIED
    %XHTML1-formvalidation1.xmlns.extra.attrib;
>

我以前从未做过 DTD,所以我什至不确定我在做什么.当我通过 W3 XHTML 验证器运行我的页面时,我得到了 80 多个错误,因为它得到了所有 XHTML 元素的重复定义.我至少在正确的轨道上吗?有什么建议吗?

I've never done DTD before, so I'm not even really exactly sure what I'm doing. When I run my page through the W3 XHTML validator, I get 80+ errors because it's getting duplicate definitions of all the XHTML elements. Am I at least on the right track? Any suggestions?

我从我的自定义 DTD 中删除了这一部分,因为事实证明它实际上是自引用的,而我从中获取模板的代码实际上是将两个 DTD 合并为一个,而不是将特定项目附加到一个:

I removed this section from my custom DTD, because it turned out that it was actually self-referencing, and the code I got the template from was really for combining two DTDs into one, not appending specific items to one:

<!ENTITY % XHTML1-formvalidation1
    PUBLIC  "-//W3C//DTD XHTML 1.1 +FormValidation 1.0//EN"
            "http://new.dandoes.net/DTD/FormValidation1.dtd" >
%XHTML1-formvalidation1;

我也删除了这个,因为它没有验证,并且似乎没有做任何事情:

I also removed this, because it wasn't validating, and didn't seem to be doing anything:

<!ENTITY % Inlspecial.extra 
  "%div.qname; " >

另外,我决定,由于我只是添加了一些额外的项目,W3 推荐的单独文件模型似乎并没有那么有用,所以我将所有内容都放入了 dtd 文件,其中的内容现在是这样的:

Additionally, I decided that since I'm only adding a handful of additional items, the separate files model recommended by W3 doesn't really seem that helpful, so I've put everything into the dtd file, the content of which is now this:

<!ATTLIST div onvalidate CDATA  #IMPLIED>
<!ENTITY % xhtml11.dtd
    PUBLIC  "-//W3C//DTD XHTML 1.1//EN"
            "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
%xhtml11.dtd;

所以现在,我没有收到任何与 DTD 相关的验证错误,但 onvalidate 属性仍然无效.

So now, I'm not getting any DTD-related validation errors, but the onvalidate attribute still is not valid.

更新:我放弃了 DTD 并添加了一个架构:http://schema.dandoes.net/FormValidation/1.0.xsd

Update: I've ditched the DTD and added a schema: http://schema.dandoes.net/FormValidation/1.0.xsd

使用 v:onvalidate 似乎可以在 Visual Studio 中进行验证,但 W3C 服务仍然不喜欢它.

Using v:onvalidate appears to validate in Visual Studio, but the W3C service still doesn't like it.

这是我使用它的页面,因此您可以查看源代码:

Here's a page where I'm using it so you can look at the source:

http://new.dandoes.net/auth

这是 w3c 验证结果的链接:

And here's the link to the w3c validation result:

http://validator.w3.org/check?uri=http://new.dandoes.net/auth&charset=(detect+automatically)&doctype=Inline&group=0

这是我能做到的,还是我仍然做错了什么?

Is this about as close as I'll be able to get with this, or am I still doing something wrong?

推荐答案

如果你希望结果是有效的 XHTML,我相信你需要使用 XML 命名空间 而不是自定义 DTD.DTD 不仅定义 语言(因此,自定义 DTD 不是真正的"XHTML),而且它会将任何读取它的浏览器扔到 怪癖模式,即使他们不会卡在文件上.

If you want the result to be valid XHTML, I believe you'll need to use XML namespaces rather than a custom DTD. Not only does the DTD define the language (and thus, a custom DTD isn't "really" XHTML), but it will throw any browsers that read it into quirks mode, even if they don't choke on the file.

另一方面,使用命名空间将生成完全有效的 XHTML(尽管并非所有验证器都可以识别命名空间并且可能无法正确验证它)并允许浏览器在(接近)标准模式下工作.

Using a namespace, on the other hand, will produce perfectly valid XHTML (though not all validators are namespace-aware and may not validate it correctly) and allow browsers to work in (near-)standards mode.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="http://example.com/ns/validation" xml:lang="en">
    <head><title>Validation Example</title></head>

    <body>
        <input id="name1" type="text" v:onvalidate="return this.value.length &gt; 0;"/>
        <input id="name2" type="text" v:validation="not empty"/>
    </body>
</html>

这篇关于扩展 XHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆