Validating XML against XSD might be the first step to take especially when building a feed Reader/Ingester. For Starters, any file like the sample below is a well-formed XML file.
and below is a sample XSD (XML Schema Definition) file.
Validating With DOMDocument
This DomValidator can be easily used like so:
The above piece of code is actually easy to understand, the most important method here is the validateFeeds() method.
Validating With XMLReader
The upside of using XMLReader over DomDocument is scalability. XMLReader can handle very large files better than DomDocument. Our class will be very similar to that of DomDocument. Also note that your libxml version is above 2.6.
We use this class too similar to how we used the DomValidator class.
So that’s it. I hope to follow this up with ingesting feeds very soon. You can reach me on firstname.lastname@example.org for feedback, I will appreciate it.