Here is the SVG file I’m trying to use the XPath on:
[url]http://mrinitialman.com/StandAlones/XML/olde_english.svg
My PHP is as follows:
[code=php]
function XMLFile($f, $val=true){
$xml = new DOMDocument();
$xml->Load($f);
if($val){$xml->validate();}
return $xml;
}
$alphabet = XMLFile(‘./Alphabets/olde_english.xml’,false);
$getletters = new DOMXPath($alphabet);
$query='(//path)’;
$letters = $getletters->evaluate($query);
echo ‘<!–‘.n.
‘Path Elements: ‘.$alphabet->getElementsByTagName(‘path’)->length.n.
‘Do we have the right file?: ‘.$alphabet->getElementsByTagName(‘title’)->item(0)->firstChild->data.n.
‘Path Elements Found by XPath: ‘.$letters->length.n.
‘–>’.n;
The first uses plain DOMDocument methods to count the path elements.
The second makes sure (by checking the title element) that we actually have the right SVG file
The third checks to see how many path elements we’ve found via the XPath method.
The XML comment results in:
[code=html]
<!–
Path Elements: 62
Do we have the right file?: Olde English Font
Path Elements Found by XPath: 0
–>
First: Check; 62 path elements found.
Second: Check; that’s the title of the right document.
Third: . . . Um, uncheck.
My ultimate plan is to use XPath to find the elements by ID attribute without having to validate the SVG file.
[/code]