I was trying to validate my SVG file just to get the IDs with getElementById(),
<?xml version="1.0"?>
<!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">
<text id="text_titulo" x="150" y="20" font-family="Arial" font-size="15px" style="font-weight:bold;">Title</text>
<text id="text_subtitulo" x="200" y="35" font-family="Arial" font-size="10px">Sub Title</text>
<g transform="translate(0,50) scale(0.1)">
<a id="a_AC" ...... >
<polygon id="polygon_AC" ....... />
</a>
</g>
</svg>
but when calling $dom->load(), it was getting the errors "failed to open stream" and "Validation failed: no DTD found !I/O warning : failed to load external entity"
so I created my own validation wrapper (I just want to find the IDs with getElementById() )
<?php
$docSVG = new DOMDocument();
$docSVG->load(realpath($filepath));
setAllId($docSVG);
function setAllId($DOMNode){
if($DOMNode->hasChildNodes()){
foreach ($DOMNode->childNodes as $DOMElement) {
if($DOMElement->hasAttributes()){
$id=$DOMElement->getAttribute("id");
if($id){
$DOMElement->setIdAttribute("id",$id);
}
}
setAllId($DOMElement);
}
}
}
?>