在 xsd 问题中使用 xhtml 命名空间 [英] Use xhtml namespaces in xsd problem

查看:33
本文介绍了在 xsd 问题中使用 xhtml 命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 xml 文件中做这样的事情:

I want to make in my xml file something like that:

<myfile>
<screen>
<img src="a.jpg"/>
</screen>
</myfile>

我尝试以这种方式进行:XML 文件

I try to make this in this way: XML file

<?xml version="1.0" encoding="UTF-8"?>

          <myfile  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="myfile.xsd">

<screen>
<img src="a.jpg"/>
</screen>
</myfile>

XSD 文件

<?xml version="1.0"?>

<xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"   xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsd:import namespace="http://www.w3.org/1999/xhtml" schemaLocation="xhtml.xsd"/>
<xsd:element name="myfile">
<xsd:element name="screen">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="xhtml:img"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:element>

但 firefox 不显示任何错误,但我看不到任何图像:/有人可以帮忙吗?

But firefox dont display any error, but i can't see any image :/ Can someone help with this ?

推荐答案

显示图片

Firefox 作为浏览器,显示以 XHTML 或 HTML 编写的网页.在这种情况下,它将显示标记为 元素的图像.

Firefox, as a browser, displays web pages written in XHTML or HTML. In that situation, it will display images marked up as <img> elements.

否则,它不会对 元素做任何特殊处理.例如,如果您在自己的自定义 XML 文档中间有 <img> 元素,Firefox 不知道它是什么.

Otherwise, it does not do anything special with <img> elements. For example, if you have <img> elements in the middle of your own custom XML document, Firefox knows nothing of what it is.

解决方案是,为了让图像正确显示,创建一个 XHTML 文档.

The solution is, in order to have the image display properly, to create an XHTML document.

命名空间

由于您专门询问了名称空间...您的 XML 文档将不会根据您的架构进行验证,因为您的架构需要 XHTML 名称空间中的元素,但您的 XML 文档中的元素不在名称空间中.

Since you asked specifically about namespaces... your XML document will not validate against your schema because your schema is expecting elements in the XHTML namespace, but the elements in your XML document are in no namespace.

要解决此问题,请更改 XML 文档的以下行

To fix that, change the following line of your XML document

<myfile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="myfile.xsd">

<myfile xmlns="http://www.w3.org/1999/xhtml"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="myfile.xsd">

默认命名空间声明 xmlns="http://www.w3.org/1999/xhtml" 说这个元素和所有没有命名空间前缀的后代都是在 XHTML 命名空间中."

The default namespace declaration xmlns="http://www.w3.org/1999/xhtml" says "this element, and all descendants, that don't have a namespace prefix, are in the XHTML namespace."

请注意,位于某个命名空间被某个模式验证是 XML 文档的独立属性.(实际上前者是元素或属性的属性,而不是整个文档的属性.)模式使用命名空间,但两者并不相同.

Note that being in a certain namespace and being validated by a certain schema are independent properties of an XML document. (Actually the former is a property of an element or attribute, not of the whole document.) Schemas use namespaces, but the two are not the same.

这篇关于在 xsd 问题中使用 xhtml 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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