Reputation: 9702
Let's say I have the following xml file:
<report>
<income>
<amount type="type1">50</amount>
<amount type="type2">100</amount>
</income>
<outcome>
<amount type="type1">75</amount>
<amount type="type2">10</amount>
</outcome>
</report>
I want to be sure that xml file contains only above tags, type attribute is only type1 or type2, and amount is only integer. What should I use to validate xml file according to specified rules? Must I do it manually (parse xml file and check each tag for rules) or is there any method like predefining template or anything else?
Upvotes: 1
Views: 67
Reputation: 272347
Sounds like you need an XML Schema
An XML schema is a description of a type of XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed by XML itself. These constraints are generally expressed using some combination of grammatical rules governing the order of elements, Boolean predicates that the content must satisfy, data types governing the content of elements and attributes, and more specialized rules such as uniqueness and referential integrity constraints.
There's a tutorial here to get you started.
Upvotes: 3