Hướng dẫn dùng xsd validator trong PHP
It’s 2017 and you still prefer using XML(Extensible Markup Language) to
JSON(JavaScript Object Notation) for data-interchange? Well, that is not the point about this article. Everything you want to say about the trade-offs of either of them has been dealt with here. But there are still a lot of systems using XML today and I can assure you that it would still be the case X years from
now.
and below is a sample XSD (XML Schema Definition) file:
Writing a XSD for your XML is actually easy to do, you make use of tools like
freeformatter or do a crash course on w3Schools. 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 XMLReaderThe 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 for feedback, I will appreciate it. Enjoy this post? Give Surajudeen Akande a like if it's helpful. 1Share
A passionate learner and elucidative teacher. I am a Full-Stack PHP Engineer who has worked extensively using PHP and modern PHP Frameworks. I also develop Front-end Applications using JS and JQuery. Discover and read more posts from Surajudeen Akande Enjoy this post? Leave a like and comment for Surajudeen |