允许在 XML 模式中使用某些 XHTML 标签? [英] Allowing certain XHTML tags in an XML Schema?

查看:29
本文介绍了允许在 XML 模式中使用某些 XHTML 标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的网站设计 XML 架构.模式中的元素之一称为评论",它应该包含用户发布的评论.我不允许使用某些 xhtml 标签:biu 用于样式设置.到目前为止,我所做的是导入 XHTML 命名空间,然后为我的 comments 元素声明一个 complexType:

I'm designing an XML Schema for my website. One of the elements in the schema is called "comments", which is supposed to contain comments posted from users. I wan't to allow certain xhtml tags to be used: b, i, and u for styling. So far what I've done is to import the XHTML namespace, and then declare a complexType for my comments element:

<import namespace="http://www.w3.org/1999/xhtml"
        schemaLocation="xhtml1-transitional.xsd" />

....

<element name="comments">
    <complexType mixed="true">
        <any minOccurs="0">
            <element ref="xhtml:u"/>
            <element ref="xhtml:b"/>
            <element ref="xhtml:i"/>
        </any>
    </complexType>
</element>

但这似乎不起作用!至少 XML Schema 不会通过 IBM XML Schema Quality Checker 进行验证.xhtml1-transitional.xsd 文件与 XML 架构位于同一文件夹中.

But this doesn't seem to work! At least the XML Schema won't validate via the IBM XML Schema Quality Checker. The xhtml1-transitional.xsd file is in the same folder as the XML Schema.

推荐答案

最简单的方法是使用 <[CDATA[ ... ]]> 部分进行注释.我认为您验证了应用程序代码中的标签,因此您不必再次在 XSD 中强制验证.

The easiest way would be to use a <[CDATA[ ... ]]> section for the comments. I think you validate the tags in your application code, so you don't have to enforce the validation in the XSD again.

由于您只需要 XSD 解决方案,我认为最简单的方法是将注释标签定义为字符串并转义 html 特殊字符:

Since you want an XSD solution only, I think the simplest way would be to define the comments tag as a string and escape the html special chars:

<xsd:element name="comments" type="xsd:string" />

我不认为将实际标签作为 XML 包含在模式中是一个好方法,因为它只是任意内容(有效 HTML 是什么,这是无效的 XML?例如 <p> 没有 </p> 是有效的 HTML,但在 XML 中无效).

I don't think, that it would be a good way to go to include the actual tags as XML in the schema, since it is just arbitrary content (what's with valid HTML, which is invalid XML? For example <p> without </p> is valid HTML, but invalid in XML).

要转义的 XML 特殊字符

The XML special characters to escape

" & ' < >

这篇关于允许在 XML 模式中使用某些 XHTML 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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