对于以下 XSD 文件:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="stringtype">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType name="inttype">
<xs:restriction base="xs:positiveInteger"/>
</xs:simpleType>
<xs:simpleType name="dectype">
<xs:restriction base="xs:decimal"/>
</xs:simpleType>
<!-- Tokens -->
<xs:complexType name="RelativeText">
<xs:attribute name="name" type="stringtype" use="required"/>
<xs:attribute name="flow" type="stringtype" use="required"/>
<xs:attribute name="amount" type="inttype" use="required"/>
</xs:complexType>
<xs:complexType name="LineText">
<xs:attribute name="name" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="BoxText">
<xs:attribute name="name" type="stringtype" use="required"/>
<xs:attribute name="width" type="dectype" use="required" />
<xs:attribute name="height" type="dectype" use="required" />
<xs:attribute name="x" type="dectype" use="required" />
<xs:attribute name="y" type="dectype" use="required" />
</xs:complexType>
<!-- Settings -->
<!-- Local Settings - per file type -->
<!-- Directories -->
<xs:complexType name="MonitorDirectoryElementType">
<xs:attribute name="path" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="OutputDirectoryElementType">
<xs:attribute name="path" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="LoggingDirectoryElementType">
<xs:attribute name="path" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="FileExtensionElementType">
<xs:attribute name="extension" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="LocalSettingsType">
<xs:all>
<xs:element name="file-type" type="FileExtensionElementType" maxOccurs="1"/>
<xs:element name="monitor-directory" type="MonitorDirectoryElementType" maxOccurs="1"/>
<xs:element name="output-directory" type="OutputDirectoryElementType" maxOccurs="1"/>
<xs:element name="log-directory" type="LoggingDirectoryElementType" maxOccurs="1"/>
</xs:all>
</xs:complexType>
<!-- Global Settings -->
<xs:complexType name="ApplicationLogFileType">
<xs:attribute name="path" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="GlobalSettingsType">
<xs:all>
<xs:element name="log-file" type="ApplicationLogFileType" maxOccurs="1"/>
</xs:all>
</xs:complexType>
<!-- Token Type Wrap Around -->
<xs:complexType name="TokensType">
<xs:choice maxOccurs="unbounded">
<xs:element name="line-text" type="LineText" />
<xs:element name="box-text" type="BoxText" />
<xs:element name="relative-text" type="RelativeText" />
</xs:choice>
</xs:complexType>
<!-- Template content -->
<xs:complexType name="templatecontenttype">
<xs:all>
<xs:element name="local-settings" type="LocalSettingsType" maxOccurs="1" />
<xs:element name="tokens" type="TokensType" maxOccurs="1"/>
</xs:all>
</xs:complexType>
<!-- Main application settings -->
<xs:complexType name="ApplicationConfigurationType">
<xs:choice maxOccurs="unbounded">
<xs:element name="global-settings" type="GlobalSettingsType" maxOccurs="1"/>
<xs:element name="template-content" type="templatecontenttype" />
</xs:choice>
</xs:complexType>
<xs:element name="ApplicationConfiguration" type="ApplicationConfigurationType" />
</xs:schema>
我希望能够与这样的 xml 一起使用:
<?xml version='1.0'?>
<ApplicationConfiguration>
<global-settings >
<log-file path="D:\applicationLog.log" />
</global-settings>
<template-content>
<local-settings>
<file-type extension=".txt" />
<monitor-directory path="D:\monitor\"/>
<output-directory path="D:\output"/>
<log-directory path= "D:\ThisInstanceLogs"/>
</local-settings>
<tokens>
<line-text name="xyz1" />
<line-text name="xyz12" />
<relative-text name="xyz123" flow="below" amount="1"/>
<line-text name="xyz1234" />
<line-text name="xyz12345" />
<box-text name="thada" width="100" height="100" x="2" y="3"/>
</tokens>
</template-content>
</ApplicationConfiguration>
在哪里
全局设置只能出现一次
模板内容 = 无限次
本地设置和令牌 - 每个一次
令牌中的元素 = 以任何顺序无限制(甚至 0 次出现)
日志文件一次&强制
. 我觉得我在这里做错了很多事情..