首页 > 解决方案 > 使用来自另一个包的 xsd 验证 xml,提供 xsd 的相对路径

问题描述

我有 fonts.xml

<!-- name="default" version="110" -->

<fonts 
     xmlns="http://www.example.org/fonts"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.example.org/fonts file:///V:\V1220\com.java.mypackage\src\main\resources\fonts\fonts.xsd">
    <font fontName="defaultRegular" fontSize="17" fontFamily="Roboto-Regular"/>
    <font fontName="defaultLight" fontSize="17" fontFamily="Roboto-Light"/>
    <font fontName="defaultMedium" fontSize="17" fontFamily="Roboto-Medium"/>
    <font fontName="defaultBold" fontSize="17" fontFamily="Roboto-Bold"/>
    <font fontName="intermediateLight" fontSize="16" fontFamily="Roboto-Light"/>
    <font fontName="intermediateRegular" fontSize="16" fontFamily="Roboto-Regular"/>
    <font fontName="intermediateMedium" fontSize="16" fontFamily="Roboto-Medium"/>
    <font fontName="intermediateBold" fontSize="16" fontFamily="Roboto-Bold"/>
    <font fontName="smallLight" fontSize="14" fontFamily="Roboto-Light"/>
    <font fontName="smallRegular" fontSize="14" fontFamily="Roboto-Regular"/>
    <font fontName="smallMedium" fontSize="14" fontFamily="Roboto-Medium"/>
    <font fontName="smallBold" fontSize="14" fontFamily="Roboto-Bold"/>
    <font fontName="smallerLight" fontSize="12" fontFamily="Roboto-Light"/>
    <font fontName="tinyLight" fontSize="10" fontFamily="Roboto-Light"/>
    <font fontName="bigRegular" fontSize="21" fontFamily="Roboto-Regular"/>
</fonts>

和 fonts.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/fonts"
xmlns:tns="http://www.example.org/fonts"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
  <xs:element name="font">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:string">
          <xs:attribute type="xs:string" name="fontName" use="required"/>
          <xs:attribute type="xs:byte" name="fontSize" use="required"/>
          <xs:attribute type="xs:string" name="fontWeight" use="optional"/>
          <xs:attribute type="xs:string" name="fontFamily" use="required"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
  <xs:element name="fonts">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="font" maxOccurs="unbounded" minOccurs="0">
          <xs:annotation>
            <xs:documentation>what can be changed here are the values from fontSize, fontWeight and fontFamily
          or you can add a new Font but DO NOT DELETE a font or CHANGE the values from the fontName</xs:documentation>
          </xs:annotation>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="fonts" type="fonts"/>


</xs:schema>

现在,如果我删除例如 fontName 属性,我会在 Eclipse 编辑器中得到一个错误。我想保持这种行为,但不给 schemaLocation 到我的 xsd 的绝对路径。我的 xsd 和 xml 文件位于不同的包中。你知道我该如何处理吗?谢谢

标签: xmleclipsevalidationxsd

解决方案


推荐阅读