Home »
Imported messages »
comp.lang.php »
Re: DOM and node
Re: DOM and node [message #173851] |
Tue, 10 May 2011 14:23 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
El 10/05/2011 13:48, smerf escribió/wrote:
> I have XML like this :
>
> <li>
> Producer:
> <strong>
> <a href="link.html">Name</a>
> </strong>
> </li>
>
>
> How to get only "Producer:" without value of <strong> node ?
>
> I would like to do it in a preety way using built-in PHP classes of DOM
> family.
>
> I can't find solution better then :
> $nodeLI->nodeValue and REGEX
>
> How do you process XML like this one?
If the structure won't change, you can do this:
<?php
$xml_string = '<?xml version="1.0" encoding="ISO-8859-1"?>
<li>
Producer:
<strong>
<a href="link.html">Name</a>
</strong>
</li>';
$doc = new DOMDocument;
libxml_use_internal_errors(TRUE);
$doc->loadXML($xml_string);
libxml_use_internal_errors(FALSE);
$lists = $doc->getElementsByTagName('li');
foreach($lists as $li){
var_dump($li->firstChild->nodeValue);
}
You can trim() the value if you wish.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|
Goto Forum:
Current Time: Tue Nov 26 22:06:39 GMT 2024
Total time taken to generate the page: 0.01649 seconds