views:

86

answers:

1

How do the SAX API-s validate XML against a schema/DTD?

My understanding is the SAX API-s read an XML doc chuck by chunk and do not store the previously read chunks in memory. So I'm not clear how the API could validate the doc without keeping it all in memory. ??

+1  A: 

You don't need to keep the whole XML tree in memory in order to validate it. Just those parts that are validated at the moment are needed to be in memory. For example, if you need to confirm to structure like that root/child*/property*, then only child-parent relationships are actually needed to be checked and thus we need to store only previous element to verify that. Of course, if sturucture is more complex, than more memory will be used to verify complex constraints.

Superfilin
Certain kinds of XML Validation require access to the document in full as explained in the Drawbacks of the SAX page on Wikipedia: http://en.wikipedia.org/wiki/Simple_API_for_XML#Drawbacks
Pascal Thivent
@Pascal, the link above says that validation of ID/IDREF relationship will require only the full list of IDs and IDREFs to be kept in memory, but not the full document.
Superfilin