views:

282

answers:

1

Anyone know how can I check the php SimpleXmlElement Object for errors?I mean if is an valid XML file?I have read the manual a lot..but i don't get it!

Best Regards,

+2  A: 

According to http://www.ibm.com/developerworks/library/x-simplexml.html (see the Error handling section) SimpleXML will not validate your file, it will only check if it is well-formed and return false if that is not the case.

An alternative is to use the PHP DOM Class, call DOMDocument::loadXML() and either write an own error handler and look at the warnings or just let it print the warnings normally. Since SimpleXML is just a DOM Wrapper you can simply cast it to a DOMDocument and viceversa.

You can also turn the validateOnParse property off and then validate it seperately with DOMDocument::validate.

Patrick Daryll Glandien