当一个xml 文件有多个schema约束是可以一个为默认的,其它的都加前缀。

department.xsd

<?xml version="1.0" encoding="UTF-8"?>
<!-- 数据文件,引用多个Schema -->
<company xmlns="http://www.example.org/company" xmlns:dept="http://www.example.org/department"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.example.org/company company.xsd 
    http://www.example.org/department department.xsd">
    <employee age="30">
        <!-- 部门名称 -->
        <dept:name>人力资源部</dept:name>
        <!-- 员工名称 -->
        <name>王小小</name>
    </employee>
</company>

company.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/department"
    xmlns:tns="http://www.example.org/department" elementFormDefault="qualified">
    <element name="name" type="string">
    </element>
</schema>

company.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- 数据文件,引用多个Schema -->
<company xmlns="http://www.example.org/company" xmlns:dept="http://www.example.org/department"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.example.org/company company.xsd 
    http://www.example.org/department department.xsd">
    <employee age="30">
        <!-- 部门名称 -->
        <dept:name>人力资源部</dept:name>
        <!-- 员工名称 -->
        <name>王小小</name>
    </employee>
</company>

Result:

schema(二)为xml文件添加多个schema约束

相关文章:

  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-12-28
猜你喜欢
  • 2021-08-31
  • 2021-06-19
  • 2022-01-19
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
  • 2021-11-01
相关资源
相似解决方案