I would like to get SVG tag content with PHP.
test.svg:
<?xml version="1.0" encoding="utf-8"?>
<!-- comment -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="202.5px" height="226.084px" viewBox="0 0 202.5 226.084" enable-background="new 0 0 202.5 226.084" xml:space="preserve">
<g>
<path d="M0,13.628c47.7940,13.628z"/>
<polygon points="108.48,207.874 145.506,196.948 145.506,204.536 108.48,214.854 "/>
<path fill="none" stroke="#000000" d="M114.55,223.959"/>
</g>
<g>
<path fill="none" stroke="#000000" d="M114.55,223.959"/>
</g>
<anythingElse>
<path fill="none" stroke="#000000" d="M114.55,223.959"/>
<anythingElse>
</svg>
php:
$svg = new SimpleXMLElement( file_get_contents( 'test.svg' ) );
$svg->registerXPathNamespace('svg', 'http://www.w3.org/2000/svg');
$svg->registerXPathNamespace('xlink', 'http://www.w3.org/1999/xlink');
Now, I would like to get the svg tag content as a string.
Desired result (hardcoded example):
$content = '<g>
<path d="M0,13.628c47.7940,13.628z"/>
<polygon points="108.48,207.874 145.506,196.948 145.506,204.536 108.48,214.854 "/>
<path fill="none" stroke="#000000" d="M114.55,223.959"/>
</g>
<g>
<path fill="none" stroke="#000000" d="M114.55,223.959"/>
</g>
<anythingElse>
<path fill="none" stroke="#000000" d="M114.55,223.959"/>
<anythingElse> ';
//EDIT:
I don't want to look for g tag: '/svg:svg/svg:g'. As there is no guarantee that inside the svg there will be a g tag. There could be more then one g tag or some other tags.
I want to get everything between the opening and closing svg tags.