FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » php xml DOM/xpath how to reference child nodes by name within foreach loop?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: php xml DOM/xpath how to reference child nodes by name within foreach loop? [message #171612 is a reply to message #171610] Wed, 12 January 2011 03:36 Go to previous messageGo to previous message
anny2work_at_gmail_do is currently offline  anny2work_at_gmail_do
Messages: 3
Registered: December 2010
Karma:
Junior Member
responding to
http://www.1-script.com/forums/php-xml-DOM-xpath-how-to-reference-child-nod es-by-name-withi-article133746--7.htm
annyphp wrote:

Denis McMahon wrote:

> On 11/01/11 22:43, inetquestion wrote:

>> Any suggestions?

>> <?php
>> $xmlDOM = new DOMDocument();
>> $xmlDOM->load("servers.xml");
>> $SERVERS =
>> $xmlDOM->getElementsByTagName("server");

> After you have $SERVERS, do this with it:

> $items = $SERVERS->length;
> $nodenames = array('hostname','offset','ntpd');
> while ($items --) {
> $server = $SERVERS->item($items);
> foreach($nodenames as $nodename) {
> $nodes = $server->getElementsByTagName($nodename);
> if ($nodes->length == 1) {
> $node = $nodes->item(0);
> echo $nodename . "=" . $node->textContent .
> "\n";
> }
> }
> echo "\n";
> }

>> ?>

>> </xml>

> that line is bad in your xml

> My output, after I fixed the xml:

> hostname=hostname02
> offset=0
> ntpd=ERROR: timeout

> hostname=hostname01
> offset=0
> ntpd=running

> Rgds

> Denis McMahon



-------------------------------------
More php xml info
http://www.phpkode.com/scripts/category/php-xml/
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Intercepting a HTTP request
Next Topic: input a section of a large file
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 07:28:46 GMT 2024

Total time taken to generate the page: 0.04439 seconds