Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XML中编写具有多个命名空间的xsd文件?_Xml_Xsd - Fatal编程技术网

如何在XML中编写具有多个命名空间的xsd文件?

如何在XML中编写具有多个命名空间的xsd文件?,xml,xsd,Xml,Xsd,当我在mec.xsd中定义XML模式时,它对元素不起作用。我如何解决这个问题?谢谢 <l:primary>XML</l:primary> XML mec.xml <?xml version="1.0" encoding="UTF-8" standalone="no"?> <people xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

当我在mec.xsd中定义XML模式时,它对元素不起作用。我如何解决这个问题?谢谢

<l:primary>XML</l:primary>
XML
mec.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<people xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://www.example.com mc.xsd"
         xmlns:l="http://www.example2.com"
         xmlns="http://www.example.com"> 
    <person>
        <name>Marcus</name>
        <language>
            <l:primary>XML</l:primary>
        </language>
    </person>
</people>

马库斯
XML
mc.xsd

<xs:schema version="1.0"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.example.com"
           xmlns="http://www.example.com"
           elementFormDefault="qualified">
    <xs:element name="people">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="person">
                    <xs:complexType mixed="true">
                        <xs:sequence>
                            <xs:element name="name" type="xs:string"/>
                            <xs:element name="language">
                                <xs:complexType mixed="true">
                                    <xs:element name="primary" type="xs:string"/>            
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>

  • 您必须使用两种模式。每个命名空间一个架构
  • 您必须使用
    xsd:import
    从不同的数据库导入xsd 命名空间

  • 您必须仅使用主模式验证xml文档 (mc.xsd

primary.xsd(导入的架构)


mc.xsd(主模式)


对不起,我已经很久没有处理过这些东西了。。。希望有人会过来帮忙。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" 
    targetNamespace="http://www.example2.com"> 
    <xs:element name="primary" type="xs:string"/>
</xs:schema>
<xs:schema version="1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.com"
    xmlns="http://www.example2.com"
    elementFormDefault="qualified">
    <xs:import namespace="http://www.example2.com" schemaLocation="primary.xsd"/>
    <xs:element name="people">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="person">
                    <xs:complexType mixed="true">
                        <xs:sequence>
                            <xs:element name="name" type="xs:string"/>
                            <xs:element name="language">
                                <xs:complexType mixed="true">
                                    <xs:sequence>
                                        <xs:element ref="primary"/>   
                                    </xs:sequence>

                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:complexType>
    </xs:element>
</xs:schema>