Use xhtml namespaces in xsd problem
I want to make in my xm开发者_高级运维l file something like that:
<myfile>
<screen>
<img src="a.jpg"/>
</screen>
</myfile>
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 file
<?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>
But firefox dont display any error, but i can't see any image :/ Can someone help with this ?
Displaying images
Firefox, as a browser, displays web pages written in XHTML or HTML. In that situation, it will display images marked up as <img>
elements.
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.
The solution is, in order to have the image display properly, to create an XHTML document.
Namespaces
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.
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">
to
<myfile xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="myfile.xsd">
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."
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.
精彩评论