XML Schema validation using the XSD -


I have an XML that looks like the bottom in which the number of items can vary from 0 to n. There is a way to write XSD to verify the schema.

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; ShoppingItems & gt; & Lt; CUSTOMERNAME & gt; John & lt; / CUSTOMERNAME & gt; & Lt; Address & gt; Walstreet, Newyork & lt; / Address & gt; & Lt; Item 1 & gt; Milk & lt; / Item 1 & gt; & Lt; Price1 & gt; 1 $ & lt; / Price1 & gt; & Lt; ITEM2 & gt; Coolie & lt; / ITEM2 & gt; & Lt; Price2 & gt; 1 $ & lt; / Price2 & gt; & Lt; ITEM3 & gt; Bread & lt; / ITEM3 & gt; & Lt; Price3 & gt; 1 $ & lt; / Price3 & gt; & Lt; Item4 & gt; Egg & lt; / Item4 & gt; & Lt; Price4 & gt; 1 $ & lt; / Price4 & gt; & Lt; Item..n & gt; Egg & LT; /Item..n> & Lt; Price..n & gt; 1 $ & lt; /Price..n> & Lt; / ShoppingItems & gt;  

It is not in the present form. The definition of an XSD is very strict - in the above case You must specify every possible shopping item type (which includes the item..One more value .. N) which is definitely not possible.

What would be better is to replace the XML file so that it is more logically structured:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; ShoppingItems & gt; & Lt; CUSTOMERNAME & gt; John & lt; / CUSTOMERNAME & gt; & Lt; Address & gt; Walstreet, Newyork & lt; / Address & gt; & Lt; Items & gt; & Lt; Item value = "1 $" & gt; Milk & lt; / Item & gt; & Lt; Item value = "3 $" & gt; Ice cream & lt; / Item & gt; & Lt; Item value = "1 $" & gt; Bread & lt; / Item & gt; & Lt; Item value = "1.5 $" & gt; Eggs & lt; / Item & gt; & Lt; / Item & gt; & Lt; / ShoppingItems & gt;   

It is possible to define this document completely with schema.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -