如何将XSD导入XML文件?

时间:2015-07-14 07:55:11

标签: xml xsd

XSD文件导入3个XS​​D,如下所示:

  <xs:import namespace="urn:swift:snl:ns.SwInt" schemaLocation="SwInt.xsd"/>
  <xs:import namespace="urn:swift:snl:ns.Sw" schemaLocation="Sw.xsd"/>     
  <xs:import namespace="urn:swift:snl:ns.SwSec" schemaLocation="SwSec.xsd"/> 

如何在从此XSD创建的XML中包含这些导入?

1 个答案:

答案 0 :(得分:0)

XSD未导入XML文件。 XSD与其他XSD文件imported or included

XSD可以与XML文件相关联。建立这种关联的最常见机制是通过schemaLocation and noNamespaceSchemaLocation

传达的提示

示例:noNamespaceSchemaLocation

在以下XML文件中,purchaseReport没有名称空间,关联的XSD可以在http://www.example.com/ReportB.xsd找到:

<purchaseReport
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://www.example.com/ReportB.xsd">

   <!-- etc. -->

</purchaseReport>

请注意ReportB.xsd没有targetNamespace

示例:schemaLocation

在以下XML文件中,purchaseReport位于http://www.example.com/Report命名空间中,关联的XSD位于http://www.example.com/Report.xsd

<purchaseReport
   xmlns="http://www.example.com/Report"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.example.com/ReportA
                       http://www.example.com/ReportA.xsd">

   <!-- etc. -->

</purchaseReport>

请注意,ReportA.xsd的{​​{1}}等于此XML文件的命名空间(targetNamespace)。

在您的特定情况下,导入其他XSD的主XSD很可能本身具有命名空间,因此您可以使用XML文件中的http://www.example.com/ReportA机制来提示主XSD的位置。管理XML文件。

相关问题