xml - XSD attribut validation for MANY elements with the same name - not possible? -




hey guys,

this situation:
have xml-file containing many (>50) configuration-properties program.

xml-content looks somehow that:

<globalconfig>     <configurationsettings>          <property name="usecolors" value="true" visible="false"/>         <property name="titlemenu" value="configurator" visible="true"/>         <property name="informationtext" value="for information please read readme.txt" visible="true"/>             [many more...]     </configurationsettings> </globalconfig> 


wanted now, creating xsd-file validating stuff. each property corresponding value-attribute has different contenttype (with restrictions enums or regex), validation-rules content of value need adepted each case. case determined "name"-attribute

i new xsd-topic, tried start with:

<xs:schema attributeformdefault="unqualified" elementformdefault="qualified" xmlns:xs="http://www.w3.org/2001/xmlschema">      <xs:element name="globalconfig">         <xs:complextype>             <xs:all>                      <xs:element name="configurationsettings">                     <xs:complextype>                         <xs:all>                              <xs:element name="property" minoccurs="0" maxoccurs="unbound">                                 <xs:complextype>                                                                     <xs:attribute name="name" fixed="usecolors" type="xs:string"/>                                         <xs:attribute name="value" default="true" type="xs:bool"/>                                         <xs:attribute name="visible" default="false" type="xs:bool"/>                                 </xs:complextype>                             </xs:element>                              <xs:element name="property" minoccurs="0" maxoccurs="unbound">                                 <xs:complextype>                                                                     <xs:attribute name="name" fixed="titlemenu" type="xs:string"/>                                         <xs:attribute name="value" default="title" type="xs:string"/>                                         <xs:attribute name="visible" default="true" type="xs:bool"/>                                 </xs:complextype>                             </xs:element>                              <xs:element name="property" minoccurs="0" maxoccurs="unbound">                                 <xs:complextype>                                                                     <xs:attribute name="name" fixed="informationtext" type="xs:string"/>                                         <xs:attribute name="value" default="see reedme.txt" type="xs:string"/>                                         <xs:attribute name="visible" default="true" type="xs:bool"/>                                 </xs:complextype>                             </xs:element>                          </xs:all>                         <xs:attribute type="xs:string" name="force"/>                     </xs:complextype>                </xs:element>              </xs:all>         </xs:complextype>     </xs:element>  </xs:schema> 

this doesnt work, , think understand why won't work: problem is, have many elements same name ("property").

i have dim feeling, won't work @ way , structure of configuration-xml needs changed, there elements different names each property.

the reason think that, second answer in following post. seems fullfill needs of questioner, had 2 elements same name , didn't want check attributes: xml schema sequence of elements same name different attribute values?

do agree, won't work given configuration-xml structure? or still possible?

thanks lot!

xsd has constraint called "element declarations consistent" in effect says if 2 sibling elements have same name, must have same type. not possible different property elements siblings of each other have different validation rules.

in xsd 1.1 there solution using type alternatives. allows make type of element conditional on values of 1 or more of attributes (in case name attribute).

is there particular reason can't design configuration file instead of

<property name="usecolors" value="true" visible="false"/> 

you use

<usecolors value="true" visible="false"/> 

the main reason using former ("generic") design schema doesn't have know possible property names. want define property names , valid values in schema, second design more appropriate.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -