xml - 使用来自另一个包的 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 文件位于不同的包中。你知道我该如何处理吗?谢谢
解决方案
推荐阅读
- python - ImportError:无法导入名称“regex_replace”
- python - 如何设置一个等于月和日的变量,然后用它做数学?
- python-3.x - 使用gremlin python进行depth4和breadth4搜索
- modeling - 我可以改变 ROC 的方向吗?
- css - 更改样式时刷新非常慢
- php - href 返回另一个 URL
- opencv - 如何成功计数片剂?
- reactjs - TypeError: Cannot read property 'color' of undefined
- r - 逻辑模型中产生的 NaN
- python - TypeError:“节点”对象不可迭代