我正在尝试使用XSD使用我的应用程序验证XML文件。 问题是我想在节点中没有顺序的XML文件。 看来我有两个选择来构建xsd。
使用xs:all
:在这种情况下,除了maxOccurs="1"
使用xs:sequence
:在这种情况下,maxOccurs
没有限制,
但节点中的顺序
有问题的节点示例:export
,lien_item
,onglet_page
....
<?xml version="1.0" encoding="UTF-8"?>
<interface xmlns="http://tempuri.org/Interface.xsd">
<general>
<theme>Windows8</theme>
<photo>standard.png</photo>
<version>1.1</version>
<is_combo_interface_enabled>true</is_combo_interface_enabled>
<appel champ="" tri="ASC" type="" visible="True" />
<affiche_bloc_questionnaire>true</affiche_bloc_questionnaire>
<affiche_kit_secours>false</affiche_kit_secours>
<affiche_check_photos>true</affiche_check_photos>
<affiche_btn_appel>true</affiche_btn_appel>
<affiche_btn_auto>true</affiche_btn_auto>
<affiche_btn_resultats_liste_resultats>true</affiche_btn_resultats_liste_resultats>
<affichage_boutons_resultats>
<tabexamen_btn_res_ind>true</tabexamen_btn_res_ind>
<tabexamen_btn_res_col>true</tabexamen_btn_res_col>
<tablistres_btn_res_ind>true</tablistres_btn_res_ind>
<tablistres_btn_res_col>true</tablistres_btn_res_col>
<tabtest_btn_res_ind>true</tabtest_btn_res_ind>
<tabtest_btn_res_col>true</tabtest_btn_res_col>
</affichage_boutons_resultats>
<affiche_panel_bas>true</affiche_panel_bas>
<affiche_btn_import>true</affiche_btn_import>
<affiche_panel_examen>false</affiche_panel_examen>
<edit_results>true</edit_results>
<ajout_personne_autorise>true</ajout_personne_autorise>
<suppression_personne_autorise>true</suppression_personne_autorise>
<modifier_inscription_autorise>true</modifier_inscription_autorise>
<signature_electronique>false</signature_electronique>
<alerte_signature>false</alerte_signature>
<nb_personnes_max>60</nb_personnes_max>
<nb_menus>6</nb_menus>
<nb_liens>4</nb_liens>
<nb_champs_session>6</nb_champs_session>
<nb_champs_personne>10</nb_champs_personne>
<nb_champs_examen_res>0</nb_champs_examen_res>
<export>
<export_item num="1" adresse="" login="" password="" zip="true" chiffre="false" showform="true">MDB</export_item>
<export_item num="2" adresse="" login="" password="" zip="true" chiffre="false" showform="true">XLS</export_item>
</export>
<menu>
<menu_item num="1">
<menu_action>CREER_SESSION</menu_action>
</menu_item>
<menu_item num="2">
<menu_action>RECHERCHER</menu_action>
</menu_item>
<menu_item num="3">
<menu_action>PARAMETRES</menu_action>
</menu_item>
</menu>
<onglet>
<onglet_page num="1">
<onglet_visible>true</onglet_visible>
</onglet_page>
<onglet_page num="2">
<onglet_visible>false</onglet_visible>
</onglet_page>
</onglet>
<default_import_directory></default_import_directory>
<default_import_file></default_import_file>
<default_export_directory></default_export_directory>
<lien>
<lien_item num="1">
<text>ASSISTANCE</text>
<action>1.exe</action>
</lien_item>
<lien_item num="2">
<text>WEB</text>
<action>2.exe</action>
</lien_item>
<lien_item num="3">
<text>NEWS</text>
<action>version_contenu.txt</action>
</lien_item>
<lien_item num="4">
<text>AIDE</text>
<action>Aide\Qui.chm</action>
</lien_item>
</lien>
</general>
<!-- nom_champ_session = Libellé du label du groupbox session -->
<session>
<champ_session num="1">
<nom_champ_session>LIB_SESSION</nom_champ_session>
<controle_session num="1">
<obligatoire_champ_session>true</obligatoire_champ_session>
<type_controle_session>textbox</type_controle_session>
<longueur_controle_session>150</longueur_controle_session>
<donnees_controle_session>texte</donnees_controle_session>
<propertie_session>Libelle</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
</controle_session>
</champ_session>
<champ_session num="2">
<nom_champ_session>CHOIX_EXAMEN</nom_champ_session>
<controle_session num="1">
<obligatoire_champ_session>false</obligatoire_champ_session>
<type_controle_session>dropdownlist</type_controle_session>
<longueur_controle_session>150</longueur_controle_session>
<donnees_controle_session>texte</donnees_controle_session>
<propertie_session>cboExamen</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
</controle_session>
</champ_session>
<champ_session num="3">
<nom_champ_session>LIB_FORMATION</nom_champ_session>
<controle_session num="1">
<obligatoire_champ_session>false</obligatoire_champ_session>
<type_controle_session>textbox</type_controle_session>
<longueur_controle_session>150</longueur_controle_session>
<donnees_controle_session>texte</donnees_controle_session>
<propertie_session>NomFormation</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
</controle_session>
</champ_session>
<champ_session num="4">
<nom_champ_session>DATES_SESSION</nom_champ_session>
<controle_session num="1">
<obligatoire_champ_session>false</obligatoire_champ_session>
<type_controle_session>datetimepicker</type_controle_session>
<longueur_controle_session>90</longueur_controle_session>
<donnees_controle_session>date</donnees_controle_session>
<propertie_session>DateDebut</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
</controle_session>
<controle_session num="2">
<obligatoire_champ_session>false</obligatoire_champ_session>
<type_controle_session>datetimepicker</type_controle_session>
<longueur_controle_session>90</longueur_controle_session>
<donnees_controle_session>date</donnees_controle_session>
<propertie_session>DateFin</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
</controle_session>
</champ_session>
<champ_session num="5">
<nom_champ_session>LIEU_FORMATION</nom_champ_session>
<controle_session num="1">
<obligatoire_champ_session>false</obligatoire_champ_session>
<type_controle_session>dropdown</type_controle_session>
<longueur_controle_session>150</longueur_controle_session>
<donnees_controle_session>texte</donnees_controle_session>
<propertie_session>LieuFormation</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
<type_datasource_session>BDD</type_datasource_session>
<valeur_datasource_session>tSession.LieuFormation</valeur_datasource_session>
<affichage_datasource_session>tSession.LieuFormation</affichage_datasource_session>
</controle_session>
</champ_session>
<champ_session num="6">
<nom_champ_session>RESPONSABLE_FORMATION</nom_champ_session>
<controle_session num="1">
<obligatoire_champ_session>false</obligatoire_champ_session>
<type_controle_session>dropdown</type_controle_session>
<longueur_controle_session>150</longueur_controle_session>
<donnees_controle_session>texte</donnees_controle_session>
<propertie_session>Formateur</propertie_session>
<modifiable_champ_session>true</modifiable_champ_session>
<type_datasource_session>BDD</type_datasource_session>
<valeur_datasource_session>tSession.Formateur</valeur_datasource_session>
<affichage_datasource_session>tSession.IdFormateur</affichage_datasource_session>
</controle_session>
</champ_session>
</session>
<personne>
<champ_personne num="1">
<nom_champ_personne>KEY</nom_champ_personne>
<obligatoire_champ_personne>false</obligatoire_champ_personne>
<mode_grille_fiche_personne>LES2</mode_grille_fiche_personne>
<controle_personne>
<type_controle_personne>textbox</type_controle_personne>
<longueur_controle_personne>0</longueur_controle_personne>
<donnees_controle_personne>texte</donnees_controle_personne>
<propertie_personne>Key</propertie_personne>
<modifiable_personne>true</modifiable_personne>
</controle_personne>
</champ_personne>
<champ_personne num="2">
<nom_champ_personne>PRESENCE</nom_champ_personne>
<obligatoire_champ_personne>false</obligatoire_champ_personne>
<mode_grille_fiche_personne>grille</mode_grille_fiche_personne>
<controle_personne>
<type_controle_personne>checkbox</type_controle_personne>
<longueur_controle_personne>30</longueur_controle_personne>
<donnees_controle_personne>texte</donnees_controle_personne>
<propertie_personne>Present</propertie_personne>
<modifiable_personne>true</modifiable_personne>
</controle_personne>
</champ_personne>
<champ_personne num="3">
<nom_champ_personne>PHOTO</nom_champ_personne>
<obligatoire_champ_personne>false</obligatoire_champ_personne>
<mode_grille_fiche_personne>FICHE</mode_grille_fiche_personne>
<controle_personne>
<type_controle_personne>image</type_controle_personne>
<longueur_controle_personne>50</longueur_controle_personne>
<donnees_controle_personne>texte</donnees_controle_personne>
<propertie_personne>Photo</propertie_personne>
<modifiable_personne>true</modifiable_personne>
</controle_personne>
</champ_personne>
<champ_personne num="4">
<nom_champ_personne>NOM</nom_champ_personne>
<obligatoire_champ_personne>true</obligatoire_champ_personne>
<mode_grille_fiche_personne>LES2</mode_grille_fiche_personne>
<controle_personne>
<type_controle_personne>textbox</type_controle_personne>
<longueur_controle_personne>100</longueur_controle_personne>
<donnees_controle_personne>texte</donnees_controle_personne>
<propertie_personne>Nom</propertie_personne>
<modifiable_personne>true</modifiable_personne>
</controle_personne>
</champ_personne>
</personne>
<examen>
<examen_lib num="1">R372m</examen_lib>
<examen_lib num="2">R386</examen_lib>
<examen_lib num="3">R389</examen_lib>
<examen_lib num="4">R390</examen_lib>
<examen_lib num="5">LV 22 R389</examen_lib>
<examen_lib num="6">LV 32 R389</examen_lib>
<examen_lib num="7">LV 42 R389</examen_lib>
<examen_lib num="8">LV 14 R386</examen_lib>
<examen_lib num="9">LV 24 R386</examen_lib>
</examen>
</interface>
XSD旨在验证上述XML:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="interface" targetNamespace="http://tempuri.org/Interface.xsd" xmlns:mstns="http://tempuri.org/Interface.xsd" xmlns="http://tempuri.org/Interface.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="interface" msdata:IsDataSet="true" msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="general">
<xs:complexType>
<xs:all>
<xs:element name="theme" type="xs:string" minOccurs="0" />
<xs:element name="photo" type="xs:string" minOccurs="0" />
<xs:element name="version" type="xs:string" minOccurs="0" />
<xs:element name="is_combo_interface_enabled" type="xs:string" minOccurs="0" />
<xs:element name="appel" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<!-- <xs:extension base="xs:string">-->
<xs:attribute name="champ" form="unqualified" type="xs:string" />
<xs:attribute name="tri" form="unqualified" type="xs:string" />
<xs:attribute name="type" form="unqualified" type="xs:string" />
<xs:attribute name="visible" form="unqualified" type="xs:string" />
<!--</xs:extension>-->
</xs:complexType>
</xs:element>
<xs:element name="affiche_bloc_questionnaire" type="xs:string" minOccurs="0" />
<xs:element name="affiche_kit_secours" type="xs:string" minOccurs="0" />
<xs:element name="affiche_check_photos" type="xs:string" minOccurs="0" />
<xs:element name="affiche_btn_appel" type="xs:string" minOccurs="0" />
<xs:element name="affiche_btn_auto" type="xs:string" minOccurs="0" />
<xs:element name="affiche_btn_resultats_liste_resultats" type="xs:string" minOccurs="0" />
<xs:element name="affichage_boutons_resultats" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="tabexamen_btn_res_ind" type="xs:string" minOccurs="0" msdata:Ordinal="0"/>
<xs:element name="tabexamen_btn_res_col" type="xs:string" minOccurs="0" msdata:Ordinal="1"/>
<xs:element name="tablistres_btn_res_ind" type="xs:string" minOccurs="0" msdata:Ordinal="2"/>
<xs:element name="tablistres_btn_res_col" type="xs:string" minOccurs="0" msdata:Ordinal="3"/>
<xs:element name="tabtest_btn_res_ind" type="xs:string" minOccurs="0" msdata:Ordinal="4"/>
<xs:element name="tabtest_btn_res_col" type="xs:string" minOccurs="0" msdata:Ordinal="5"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="affiche_panel_bas" type="xs:string" minOccurs="0" />
<xs:element name="affiche_btn_import" type="xs:string" minOccurs="0" />
<xs:element name="affiche_panel_examen" type="xs:string" minOccurs="0" />
<xs:element name="build" type="xs:string" minOccurs="0" />
<xs:element name="edit_results" type="xs:string" minOccurs="0" />
<xs:element name="ajout_personne_autorise" type="xs:string" minOccurs="0" />
<xs:element name="suppression_personne_autorise" type="xs:string" minOccurs="0" />
<xs:element name="modifier_inscription_autorise" type="xs:string" minOccurs="0" />
<xs:element name="signature_electronique" type="xs:string" minOccurs="0" />
<xs:element name="alerte_signature" type="xs:string" minOccurs="0" />
<xs:element name="nb_personnes_max" type="xs:string" minOccurs="0" />
<xs:element name="nb_menus" type="xs:string" minOccurs="0" />
<xs:element name="nb_liens" type="xs:string" minOccurs="0" />
<xs:element name="nb_champs_session" type="xs:string" minOccurs="0" />
<xs:element name="nb_champs_personne" type="xs:string" minOccurs="0" />
<xs:element name="nb_champs_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="export" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="export_item" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="export_item_Text" msdata:Ordinal="4">
<xs:extension base="xs:string">
<xs:attribute name="num" form="unqualified" type="xs:string" />
<xs:attribute name="adresse" form="unqualified" type="xs:string" />
<xs:attribute name="login" form="unqualified" type="xs:string" />
<xs:attribute name="password" form="unqualified" type="xs:string" />
<xs:attribute name="zip" form="unqualified" type="xs:string" />
<xs:attribute name="chiffre" form="unqualified" type="xs:string" />
<xs:attribute name="showform" form="unqualified" type="xs:string" />
<xs:attribute name="maille" form="unqualified" type="xs:string" />
<xs:attribute name="argument1" form="unqualified" type="xs:string" />
<xs:attribute name="local_directory" form="unqualified" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="menu" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="menu_item" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="menu_action" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="onglet" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="onglet_page" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="onglet_visible" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="import" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="import_item" nillable="true" minOccurs="0" maxOccurs="unbounded" msdata:Ordinal="1">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="import_item_Text" msdata:Ordinal="2">
<xs:extension base="xs:string">
<xs:attribute name="num" form="unqualified" type="xs:string" />
<xs:attribute name="type" form="unqualified" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="default_import_directory" type="xs:string" minOccurs="0" />
<xs:element name="default_import_file" type="xs:string" minOccurs="0" />
<xs:element name="default_export_directory" type="xs:string" minOccurs="0" />
<xs:element name="lien" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="lien_item" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="text" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="action" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="champ_session" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nom_champ_session" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="controle_session" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="obligatoire_champ_session" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="type_controle_session" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="longueur_controle_session" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
<xs:element name="donnees_controle_session" type="xs:string" minOccurs="0" msdata:Ordinal="3" />
<xs:element name="propertie_session" type="xs:string" minOccurs="0" msdata:Ordinal="4" />
<xs:element name="modifiable_champ_session" type="xs:string" minOccurs="0" msdata:Ordinal="5" />
<xs:element name="type_datasource_session" type="xs:string" minOccurs="0" msdata:Ordinal="6" />
<xs:element name="valeur_datasource_session" type="xs:string" minOccurs="0" msdata:Ordinal="7" />
<xs:element name="affichage_datasource_session" type="xs:string" minOccurs="0" msdata:Ordinal="8" />
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="personne">
<xs:complexType>
<xs:sequence>
<xs:element name="champ_personne" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nom_champ_personne" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="obligatoire_champ_personne" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="mode_grille_fiche_personne" type="xs:string" minOccurs="0" msdata:Ordinal="2" />
<xs:element name="controle_personne" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="type_controle_personne" type="xs:string" minOccurs="0" />
<xs:element name="longueur_controle_personne" type="xs:string" minOccurs="0" />
<xs:element name="donnees_controle_personne" type="xs:string" minOccurs="0" />
<xs:element name="propertie_personne" type="xs:string" minOccurs="0" />
<xs:element name="type_datasource_personne" type="xs:string" minOccurs="0" />
<xs:element name="valeur_datasource_personne" type="xs:string" minOccurs="0" />
<xs:element name="affichage_datasource_personne" type="xs:string" minOccurs="0" />
<xs:element name="modifiable_personne" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="examen">
<xs:complexType>
<xs:sequence>
<xs:element name="examen_lib" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:ColumnName="examen_lib_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="examen_res">
<xs:complexType>
<xs:sequence>
<xs:element name="champ_examen_res" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nom_champ_examen_res" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
<xs:element name="obligatoire_champ_examen_res" type="xs:string" minOccurs="0" msdata:Ordinal="1" />
<xs:element name="controle_examen_res" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="type_controle_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="longueur_controle_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="donnees_controle_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="propertie_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="type_datasource_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="valeur_datasource_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="affichage_datasource_examen_res" type="xs:string" minOccurs="0" />
<xs:element name="modifiable_examen_res" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="num" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
请问您有什么想法吗?
答案 0 :(得分:1)
当您尝试根据XSD验证XML时,您将收到Xerces-J提供的以下错误:
[错误] try.xsd:15:21:cos-all-restricted.2:{max>} 'all'模型组中的元素必须为0或1.值'unbounded' 元素'appel'无效。
这是一条正确的错误消息。如果您想要重复其任何元素,则无法使用<svg
xmlns="http://www.w3.org/2000/svg"
width="445" height="319"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<source><![CDATA[Andrew->China: Says Hello
Note right of China: China thinks\nabout it
China-->Andrew: How are you?
Andrew->>China: I am good thanks!]]></source>
<!-- SVG content here -->
</svg>
。
前进的方向是通过xsd:all
放弃支持无序元素的需要,而是使用xsd:all
。虽然对元素进行排序可能看起来不太理想,但在实践中,有序元素工作正常并避免基数(如上所述)和Unique Particle Attribution违规问题(通过xsd:sequence
试图绕过问题时常见问题)。
答案 1 :(得分:1)
如果你只是摆脱了maxOccurs =&#34;无界&#34;看起来你可以得到xs:all。在您的onglet,留置权和导出元素上。这些元素不会在您的示例中重复,即使它们的子元素仍包含无界集合。
另外,为了便于阅读和使用JAXB和xsd.exe等工具更清晰地生成代码,我更喜欢广泛引用命名的complexType元素。例如:
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo.bar"
xmlns:myprefix="http://foo.bar"
>
<!-- ... -->
<xs:complexType name="export">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="export_item">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="num" type="xs:unsignedByte" use="required" />
<xs:attribute name="adresse" type="xs:string" use="required" />
<xs:attribute name="login" type="xs:string" use="required" />
<xs:attribute name="password" type="xs:string" use="required" />
<xs:attribute name="zip" type="xs:boolean" use="required" />
<xs:attribute name="chiffre" type="xs:boolean" use="required" />
<xs:attribute name="showform" type="xs:boolean" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- ... -->
<xs:all>
<!-- ... -->
<xs:element minOccurs="0" name="relation" type="myprefix:lien"/>
<xs:element minOccurs="0" name="export" type="myprefix:export"/>
<!-- ... -->
</xs:all>
(在生产代码中,我实际上倾向于不使用内联xs:complexType,而是从上面重新分解出一个命名的export_item类型。)
答案 2 :(得分:0)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- XML Schema Generated from XML Document on Mon Jun 01 2015 16:20:21 GMT+0200 -->
<!-- with XmlGrid.net Free Online Service http://xmlgrid.net -->
<xs:element name="interface">
<xs:complexType>
<xs:sequence>
<xs:element name="general">
<xs:complexType>
<xs:sequence>
<xs:element name="theme" type="xs:string"></xs:element>
<xs:element name="photo" type="xs:string"></xs:element>
<xs:element name="version" type="xs:double"></xs:element>
<xs:element name="is_combo_interface_enabled" type="xs:string"></xs:element>
<xs:element name="appel">
<xs:complexType>
<xs:attribute name="champ" type="xs:string"></xs:attribute>
<xs:attribute name="tri" type="xs:string"></xs:attribute>
<xs:attribute name="type" type="xs:string"></xs:attribute>
<xs:attribute name="visible" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="affiche_bloc_questionnaire" type="xs:string"></xs:element>
<xs:element name="affiche_kit_secours" type="xs:string"></xs:element>
<xs:element name="affiche_check_photos" type="xs:string"></xs:element>
<xs:element name="affiche_btn_appel" type="xs:string"></xs:element>
<xs:element name="affiche_btn_auto" type="xs:string"></xs:element>
<xs:element name="affiche_btn_resultats_liste_resultats" type="xs:string"></xs:element>
<xs:element name="affichage_boutons_resultats">
<xs:complexType>
<xs:sequence>
<xs:element name="tabexamen_btn_res_ind" type="xs:string"></xs:element>
<xs:element name="tabexamen_btn_res_col" type="xs:string"></xs:element>
<xs:element name="tablistres_btn_res_ind" type="xs:string"></xs:element>
<xs:element name="tablistres_btn_res_col" type="xs:string"></xs:element>
<xs:element name="tabtest_btn_res_ind" type="xs:string"></xs:element>
<xs:element name="tabtest_btn_res_col" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="affiche_panel_bas" type="xs:string"></xs:element>
<xs:element name="affiche_btn_import" type="xs:string"></xs:element>
<xs:element name="affiche_panel_examen" type="xs:string"></xs:element>
<xs:element name="edit_results" type="xs:string"></xs:element>
<xs:element name="ajout_personne_autorise" type="xs:string"></xs:element>
<xs:element name="suppression_personne_autorise" type="xs:string"></xs:element>
<xs:element name="modifier_inscription_autorise" type="xs:string"></xs:element>
<xs:element name="signature_electronique" type="xs:string"></xs:element>
<xs:element name="alerte_signature" type="xs:string"></xs:element>
<xs:element name="nb_personnes_max" type="xs:int"></xs:element>
<xs:element name="nb_menus" type="xs:int"></xs:element>
<xs:element name="nb_liens" type="xs:int"></xs:element>
<xs:element name="nb_champs_session" type="xs:int"></xs:element>
<xs:element name="nb_champs_personne" type="xs:int"></xs:element>
<xs:element name="nb_champs_examen_res" type="xs:int"></xs:element>
<xs:element name="export">
<xs:complexType>
<xs:sequence>
<xs:element name="export_item" maxOccurs="unbounded" type="xs:string">
<xs:complexType>
<xs:attribute name="num" type="xs:int"></xs:attribute>
<xs:attribute name="adresse" type="xs:string"></xs:attribute>
<xs:attribute name="login" type="xs:string"></xs:attribute>
<xs:attribute name="password" type="xs:string"></xs:attribute>
<xs:attribute name="zip" type="xs:string"></xs:attribute>
<xs:attribute name="chiffre" type="xs:string"></xs:attribute>
<xs:attribute name="showform" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="menu">
<xs:complexType>
<xs:sequence>
<xs:element name="menu_item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="menu_action" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="onglet">
<xs:complexType>
<xs:sequence>
<xs:element name="onglet_page" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="onglet_visible" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="default_import_directory"></xs:element>
<xs:element name="default_import_file"></xs:element>
<xs:element name="default_export_directory"></xs:element>
<xs:element name="lien">
<xs:complexType>
<xs:sequence>
<xs:element name="lien_item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="text" type="xs:string"></xs:element>
<xs:element name="action" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="session">
<xs:complexType>
<xs:sequence>
<xs:element name="champ_session" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nom_champ_session" type="xs:string"></xs:element>
<xs:element name="controle_session">
<xs:complexType>
<xs:sequence>
<xs:element name="obligatoire_champ_session" type="xs:string"></xs:element>
<xs:element name="type_controle_session" type="xs:string"></xs:element>
<xs:element name="longueur_controle_session" type="xs:int"></xs:element>
<xs:element name="donnees_controle_session" type="xs:string"></xs:element>
<xs:element name="propertie_session" type="xs:string"></xs:element>
<xs:element name="modifiable_champ_session" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="personne">
<xs:complexType>
<xs:sequence>
<xs:element name="champ_personne" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="nom_champ_personne" type="xs:string"></xs:element>
<xs:element name="obligatoire_champ_personne" type="xs:string"></xs:element>
<xs:element name="mode_grille_fiche_personne" type="xs:string"></xs:element>
<xs:element name="controle_personne">
<xs:complexType>
<xs:sequence>
<xs:element name="type_controle_personne" type="xs:string"></xs:element>
<xs:element name="longueur_controle_personne" type="xs:int"></xs:element>
<xs:element name="donnees_controle_personne" type="xs:string"></xs:element>
<xs:element name="propertie_personne" type="xs:string"></xs:element>
<xs:element name="modifiable_personne" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="examen">
<xs:complexType>
<xs:sequence>
<xs:element name="examen_lib" maxOccurs="unbounded" type="xs:string">
<xs:complexType>
<xs:attribute name="num" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="xmlns" type="xs:string"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
从XML文件生成的XSD