note 49660 deleted from function.dom-domelement-getattribute by didou

From: Date: Sat, 02 Apr 2005 22:29:46 +0000
Subject: note 49660 deleted from function.dom-domelement-getattribute by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-87372@lists.php.net to get a copy of this message
Note Submitter: tw3k at tw3k dot net ---- A simple example using getAttribute. $xml = <<< XML <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE article PUBLIC "-//OASIS//DTD Simplified DocBook XML V4.1.2.5//EN" "http://www.oasis-open.org/docbook/xml/simple/4.1.2.5/sdocbook.dtd"> <article> <title id="Site" lang="en" pagenum="1" revisionflag="added" role="Web Page">My Site</title> <section id="Welcome" label="Active" lang="en" revisionflag="added" role="Content Page"> <title id="Intro" lang="en" pagenum="1" revisionflag="added">Welcome</title> <para> <inlinemediaobject> <imageobject> <imagedata fileref="img/image.jpg" format="JPG" width="150px" depth="150px" /> </imageobject> <textobject> <phrase>Alternative image text.</phrase> </textobject> </inlinemediaobject> Paragraph One. </para> <para>Paragraph two.</para> <para>Paragraph three.</para> </section> </article> XML; $dom = DomDocument::loadXML($xml); $xpath = new domxpath($dom); $imagedata = $xpath->query("//article/section[@id = 'Welcome']/para/inlinemediaobject/imageobject/imagedata"); $imagephrase = $xpath->query("//article/section[@id = 'Welcome']/para/inlinemediaobject/textobject/phrase"); $image = image($imagedata,$imagephrase); echo "<pre>"; print_r($image); echo "</pre>"; function image($imagedata,$imagephrase) { foreach ($imagedata as $img) { foreach ($imagephrase as $node) { $alt = $node->textContent; } $fileref = $img -> getAttribute('fileref'); $width = $img -> getAttribute('width'); $depth = $img -> getAttribute('depth'); $imageArray = array("src" => $fileref, "width" => $width, "height" => $depth, "alt" => $alt); } return $imageArray; } /*************/ Expected result: Array ( [src] => img/image.jpg [width] => 150px [height] => 150px [alt] => Alternative image text. )

« previous php.notes (#87372) next »