xml schema Validation script prevent nesting



I am trying to create an xsd file run against our web.config files. I am trying to catch human error and prevent nesting of tags. Example of bad xml:



<applicationSettings>
<app.MySettings>
<setting name="FirstName" serializeAs="String">
<value>John</value>
<setting name="LastName" serializeAs="String">
<value>Smith</value>
</setting>
</setting>
</app.MySettings>
<applicationSettings>


You will notice the Setting "LastName" is nested inside of "FirstName". The correct format is:



<applicationSettings>
<app.MySettings>
<setting name="FirstName" serializeAs="String">
<value>John</value>
</setting>
<setting name="LastName" serializeAs="String">
<value>Smith</value>
</setting>
</app.MySettings>
<applicationSettings>


So, I'm trying to create a schema to run it against. I have this so far:



<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://ift.tt/tphNwY">
<xs:element name="applicationSettings">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:sequence>
<xs:element name="app.mysettings">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:sequence>
<xs:element name="setting">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="1">
<xs:sequence>
<xs:element type="xs:short" name="value"/>
</xs:sequence>
<xs:attribute type="xs:string" name="name"/>
<xs:attribute type="xs:string" name="serializeAs"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>


Something is wrong because I get back its valid which it shouldn't be? If this is the wrong way to do this (using schema) please let me know of a better way.


Thanks!


D H


No comments:

Post a Comment