如何在xsd中添加特定的命名空间

时间:2014-05-13 17:54:37

标签: xml namespaces xsd

我在我的xml中添加了一个命名空间,但我不知道在我的xsd中要做什么才有效。我添加了两个名称空间:sysadminnetwork

我的xml代码:

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


xmlns:sysadmin="http://admin.ecolefrancomaghrebine.net/"

 xmlns:network="http://reseau.ecolefrancomaghrebine.net/">

<computer id="1">
<model>Macintosh PowerBook G3</model>
<sysadmin:service>21/09/32000</sysadmin:service>
<network:ip>134.158.69.203</network:ip>
<system>
<sysadmin:nom>MacOS</sysadmin:nom>
<version>X</version>
</system>
<ram sysadmin:unite="Mo">384</ram>
<disk sysadmin:unite="Go">20</disk>
<processor>Motorola PowerPC G3</processor>
<clock>400 Mhz</clock>
<administrator src="jr.jpg">Jean-René Rouet</administrator>
</computer>

</computers>

我的xsd代码:

<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml file:///C:/Users/OMARO-TAYTA/Documents/xml/computers.xml?>

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:sysadmin="http://admin.ecolefrancomaghrebine.net"
xmlns:network="http://reseau.ecolefrancomaghrebine.net"
elementFormDefault="qualified" attributeFormDefault="unqualified">


<!-- edited with XMLSpy v2008 sp1 (http://www.altova.com) by info (info) -->
    <xs:element name="computers" type="typecomputers"/>
    <xs:complexType name="typecomputers">
        <xs:sequence>
            <xs:element name="computer" type="typecomputer" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="typecomputer">
        <xs:sequence>
            <xs:element name="model" type="xs:string"/>
                        <xs:element name="service" type="sysadmin:string" />
                                    <xs:element name="ip" type="network:string"/>
                        <xs:element name="system">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="nom" type="sysadmin:string"/>
                        <xs:element name="version" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="ram">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:integer">
                            <xs:attribute name="unite" type="sysadmin:string"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="disk">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:integer">
                            <xs:attribute name="unite" type="sysadmin::string"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
            <xs:element name="processor" type="xs:string"/>
            <xs:element name="clock" type="xs:string"/>
            <xs:element name="administrator">
                <xs:complexType>
                    <xs:simpleContent>
                        <xs:extension base="xs:string">
                            <xs:attribute name="src" type="xs:string"/>
                        </xs:extension>
                    </xs:simpleContent>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="id" type="xs:integer" use="required"/>
    </xs:complexType>
</xs:schema>

我收到错误:

'sysadmin:string' must refer to an existing simple or complex type.
Error location: xs:schema / xs:complexType / xs:sequence / xs:element / @type
Details
src-resolve.4.2: Cannot resolve declaration or definition 'sysadmin:string'.

1 个答案:

答案 0 :(得分:1)

在XSD中,您需要为XML实例中使用的每个命名空间定义单独的模式文档;如果引用该命名空间中定义的任何元素(等),则需要使用xs:import来引用另一个命名空间的模式文档。