class SVGReader {
const DEFAULT_WIDTH = 512;
const DEFAULT_HEIGHT = 512;
+ const NS_SVG = 'http://www.w3.org/2000/svg';
private $reader = null;
private $mDebug = false;
$keepReading = $this->reader->read();
}
- if ( $this->reader->name != 'svg' ) {
+ if ( $this->reader->localName != 'svg' || $this->reader->namespaceURI != self::NS_SVG ) {
throw new MWException( "Expected <svg> tag, got ".
- $this->reader->name );
+ $this->reader->localName . " in NS " . $this->reader->namespaceURI );
}
$this->debug( "<svg> tag is correct." );
$this->handleSVGAttribs();
$exitDepth = $this->reader->depth;
$keepReading = $this->reader->read();
while ( $keepReading ) {
- $tag = $this->reader->name;
+ $tag = $this->reader->localName;
$type = $this->reader->nodeType;
+ $isSVG = ($this->reader->namespaceURI == self::NS_SVG);
$this->debug( "$tag" );
- if ( $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
+ if ( $isSVG && $tag == 'svg' && $type == XmlReader::END_ELEMENT && $this->reader->depth <= $exitDepth ) {
break;
- } elseif ( $tag == 'title' ) {
+ } elseif ( $isSVG && $tag == 'title' ) {
$this->readField( $tag, 'title' );
- } elseif ( $tag == 'desc' ) {
+ } elseif ( $isSVG && $tag == 'desc' ) {
$this->readField( $tag, 'description' );
- } elseif ( $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
+ } elseif ( $isSVG && $tag == 'metadata' && $type == XmlReader::ELEMENT ) {
$this->readXml( $tag, 'metadata' );
} elseif ( $tag !== '#text' ) {
$this->debug( "Unhandled top-level XML tag $tag" );
}
$keepReading = $this->reader->read();
while( $keepReading ) {
- if( $this->reader->name == $name && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
+ if( $this->reader->localName == $name && $this->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::END_ELEMENT ) {
break;
} elseif( $this->reader->nodeType == XmlReader::TEXT ){
$this->metadata[$metafield] = trim( $this->reader->value );
return;
}
// TODO: find and store type of xml snippet. metadata['metadataType'] = "rdf"
- $this->metadata[$metafield] = $this->reader->readInnerXML();
+ $this->metadata[$metafield] = trim( $this->reader->readInnerXML() );
$this->reader->next();
}
$exitDepth = $this->reader->depth;
$keepReading = $this->reader->read();
while( $keepReading ) {
- if( $this->reader->name == $name && $this->reader->depth <= $exitDepth
+ if( $this->reader->localName == $name && $this->reader->depth <= $exitDepth
&& $this->reader->nodeType == XmlReader::END_ELEMENT ) {
break;
- } elseif ( $this->reader->nodeType == XmlReader::ELEMENT ) {
- switch( $this->reader->name ) {
+ } elseif ( $this->reader->namespaceURI == self::NS_SVG && $this->reader->nodeType == XmlReader::ELEMENT ) {
+ switch( $this->reader->localName ) {
case 'animate':
case 'set':
case 'animateMotion':
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Wikimedia logo" viewBox="-599 -599 1198 1198" width="1024" height="1024">
+<defs>
+ <clipPath id="mask">
+ <path d="M 47.5,-87.5 v 425 h -95 v -425 l -552,-552 v 1250 h 1199 v -1250 z"/>
+ </clipPath>
+</defs>
+<g clip-path="url(#mask)">
+ <circle id="green parts" fill="#396" r="336.5"/>
+ <circle id="blue arc" fill="none" stroke="#069" r="480.25" stroke-width="135.5"/>
+</g>
+<circle fill="#900" cy="-379.5" r="184.5" id="red circle"/>
+</svg>
\ No newline at end of file