Question

Suppose I have an XML document that lists all of the sales made for some items. Amongst a list of price values, there are also "total" elements that is the sum of some set of items. The XML document is generated from somewhere, and I would like to validate the XML to verify that

  1. The form is correct
  2. The content is correct. For example, the total of a set of child elements is equal to the sum of all of the values associated with each child.

The XML documents are used as the standard medium between multiple programs, so it is important that the data is accurate. Currently there are checks done by the XML exporter, but I am wondering whether it is possible to validate the XML itself at the end to ensure that it is correct? And only if it is correct would it be valid?

Was it helpful?

Solution

XSD is useful for validating the XML is in a proper format and may help with "1. The form is correct". For example, XSD could be used to validate someone hasn't entered an item SKU where a price was needed.

However, XSD not a good tool for validating business logic as in "2. The content is correct". For that, you will probably need to custom validate the logic using your programming language of choice, perhaps with the help of something like XPath to extract the elements.

-Larry

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top