2

I am validating a SVG document (which I believe to be valid) against the SVG spec. I'm using XMLReader in PHP, and would rather stick with that as I will be using XMLReader elsewhere; that said if there are other stream-based readers that will do this easier/better, do let me me know.

OK, here's some code:

    // Set some values for the purpose of this example
    $this->path = '/Users/jon/Development/Personal/Visualised/master/test-assets/import-png.svg';
    $xsdPath = '/Users/jon/Development/Personal/Visualised/master/test-assets/xsd/SVG.xsd';

    $reader = new XMLReader();
    $reader->open($this->path);
    $valid = $reader->setSchema($xsdPath);
    $reader->close();

OK, so the XSD files I've got in my xsd folder are:

It seems that the parser imports the second and third XSD from the first - I want any dependencies to be stored on disk, not retrieved from the internet.

OK, here's the output:

    XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}import': Skipping import of schema located at '/Users/jon/Development/Personal/Visualised/master/test-assets/xsd/xml.xsd' for the namespace 'http://www.w3.org/XML/1998/namespace', since this namespace was already imported with the schema located at 'http://www.w3.org/2001/xml.xsd'. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45

    Warning: XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The attribute 'type' is not allowed. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45

    Warning: XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The attribute 'type' is not allowed. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45

    Warning: XMLReader::setSchema(): Element '{http://www.w3.org/2001/XMLSchema}attribute': The attribute 'type' is not allowed. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45

    Warning: XMLReader::setSchema(): Unable to set schema. This must be set prior to reading or schema contains errors. in /Users/jon/Development/Personal/Visualised/master/lib/Visualised/Document.php on line 45

It seems like maybe I have imported the wrong version of a schema somewhere - I found all the XSD docs just through a web search. Any ideas?

Edit: the last error suggests the schema should be set before reading the document. OK, so I've changed the code to this:

$reader = new XMLReader();
$valid = $reader->setSchema($xsdPath);
$reader->open($this->path);
$reader->close();

-- some of the initial warnings go, but I still get the Unable to set schema one.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Hmm, I've converted the svg XSD to RelaxNG [here](http://debeissat.nicolas.free.fr/XSDtoRNG.php) and switched `setSchema` to `setRelaxNGSchema` - and I get the same result. – halfer Mar 11 '12 at 01:49
  • Interestingly, `setRelaxNGSchema` seems to need to be called after the document is set (source: https://bugs.php.net/bug.php?id=46978), whereas I think it's the other way around for `setSchema`. – halfer Mar 11 '12 at 02:09
  • See http://stackoverflow.com/questions/3510986/where-can-i-find-a-valid-svg-xml-schema-for-ecore-generation. – Erik Dahlström Mar 12 '12 at 12:59
  • Much appreciated @ErikDahlström - I will follow that up when I get a moment (if my PHP errors turn out to be due to my using the wrong XSD files, or if I can use a DTD in preference to an XSD/NRG then you can have the bounty I planned for this question). – halfer Mar 12 '12 at 14:33
  • @ErikDahlström - thank you! I'd been fighting with this one for ages. With a bit of code fiddling I've now successfully validated against the DTD successfully. If you'd like +100, please add your link below; I'll set up a bounty and award it to you. – halfer Mar 13 '12 at 22:09

1 Answers1

2

The XSD file for SVG you link to is from an old working draft version of SVG 1.1. There's currently no officially supported XML schema for SVG 1.1. Please see this answer for more details.

Community
  • 1
  • 1
Erik Dahlström
  • 59,452
  • 12
  • 120
  • 139