Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1485

Re: DOM and node

From "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid>
Newsgroups comp.lang.php
Subject Re: DOM and node
Date 2011-05-10 16:23 +0200
Organization http://alvaro.es/
Message-ID <iqbhor$ad5$1@dont-email.me> (permalink)
References <4dc92604$1@news.home.net.pl>

Show all headers | View raw


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
--

Back to comp.lang.php | Previous | Next | Find similar | Unroll thread


Thread

Re: DOM and node "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2011-05-10 16:23 +0200

csiph-web