xml icon indicating copy to clipboard operation
xml copied to clipboard

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

Open kamilszewczyk opened this issue 5 years ago • 4 comments

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?

kamilszewczyk avatar Mar 23 '20 11:03 kamilszewczyk

where did you found this code?

staabm avatar Mar 23 '20 11:03 staabm

@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

kamilszewczyk avatar Mar 23 '20 12:03 kamilszewczyk

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

staabm avatar Mar 23 '20 14:03 staabm

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.

evert avatar Mar 23 '20 21:03 evert