2012-03-11 5 views
3

SVG 사양과 비교하여 SVG 문서 (유효하다고 생각 됨)의 유효성을 검사하고 있습니다. 저는 PHP에서 XMLReader를 사용하고 있습니다. 다른 곳에서는 XMLReader를 사용할 것이기 때문에이를 고수 할 것입니다. 더 쉽고/좋을 다른 스트림 기반 독자가 있다면 나에게 알려줘.XMLReader를 사용하여 PHP에서 SVG 파일 유효성 검사

확인, 여기에 몇 가지 코드입니다 :

// 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(); 

확인, 그래서 내 xsd 폴더에있어 한 XSD 파일은 다음과 같습니다

파서가 첫 번째에서 두 번째 및 세 번째 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 하나를 얻을 -

$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