2012-03-11 7 views
3

私はSVG仕様(これは私が有効であると信じている)をSVG仕様に対して検証しています。私はPHPでXMLReaderを使用しています。私はXMLReaderを他の場所で使用しているので、それに固執します。他のストリームベースの読者がこれをもっと簡単に/もっとうまくやってくれたら、私に知らせてください。XMLReaderを使用してPHPでSVGファイルを検証する

OKは、ここにいくつかのコードです:

// 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、私は私のxsdフォルダ内に持っているXSDファイルは、次のとおりです。

パーサーが最初から2番目と3番目のXSDをインポートしたようです - インターネットから取得しないで、依存関係をディスクに保存します。

OKは、ここでは出力です:

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 

それは多分、私がどこかにスキーマの間違ったバージョンをインポートしているように思える - 私はちょうどウェブ検索を通じて、すべてのXSDドキュメントを見つけました。何か案は?

編集:最後のエラーは、ドキュメントを読む前にスキーマを設定する必要があることを示しています。最初の警告の一部が行くが、私はまだUnable to set schema 1を得る -

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

:OK、私はこれにコードを変更しました。

+0

私はsvg XSDをRelaxNG [ここ](http://debeissat.nicolas.free.fr/XSDtoRNG.php)に変換し、 'setSchema'を' setRelaxNGSchema'に切り替えました - そして私は同じ結果を得ます。 – halfer

+0

興味深いことに、 'setRelaxNGSchema'は、ドキュメントが設定された後に呼び出される必要があると思われます(ソース:https://bugs.php.net/bug.php?id=46978)。一方、' setSchema '。 – halfer

+0

http://stackoverflow.com/questions/3510986/where-can-i-find-a-valid-svg-xml-schema-for-ecore-generationを参照してください。 –

答えて

0

あなたがリンクしているSVG用のXSDファイルは、SVG 1.1の古い作業用ドラフトバージョンのものです。現在、SVG 1.1には公式にサポートされているXMLスキーマはありません。詳細はthis answerをご覧ください。

+0

明日賞金を授与する - それはすぐに許可されません。 – halfer

関連する問題