sabre-io / xml

sabre/xml is an XML library that you may not hate.
http://sabre.io/xml/
BSD 3-Clause "New" or "Revised" License
516 stars 77 forks source link

Reader::parse() and Service::parse() return different values #181

Open kamilszewczyk opened 4 years ago

kamilszewczyk commented 4 years ago

Using sabre with XSD validation I'm getting unexpected result when using the XSD snippet from documentation. There's actually 2 problems with suggested solution: $service = new Sabre\Xml\Service(); $reader = $service->getReader(); $validXml = $reader->setSchema('myschema.xsd') if ($validXml) { $reader->xml($xml); print_r($reader->parse()); } will not work as the Schema needs to be set after xml() method call. Additionally the parse() method is returning root element array with name, value, and attributes keys. Looking at code this happens because Service::parse() is returning $result['value'] while Reader::parse() is returning $result.

Can you please either correct the code, to always have same result, or at least update the documentation to make it clear what to expect?

staabm commented 4 years ago

where did you found this code?

kamilszewczyk commented 4 years ago

@staabm Which code exactly? Suggested solution is on https://sabre.io/xml/reading at the end of that page. Reader::parse(): https://github.com/sabre-io/xml/blob/03a31cad79abbcef81e7aff28e56a9d257a0dae2/lib/Reader.php#L56 Service::parse(): https://github.com/sabre-io/xml/blob/03a31cad79abbcef81e7aff28e56a9d257a0dae2/lib/Service.php#L112

staabm commented 4 years ago

are you willing to provide a fix in https://github.com/sabre-io/sabre.io/blob/master/source/xml/reading.md ?

evert commented 4 years ago

The reader and service having slightly different signatures is definitely a bit strange in hindsight, but definitely by design. I expect most people to use the service, and the service is meant to be most user-friendly frontend for all of this.