You are here: Re: php & xml questions « PHP Programming Language « IT news, forums, messages
Re: php & xml questions

Posted by Malcolm Dew-Jones on 10/14/35 11:18

Stefano (texstefano@libero.it) wrote:
: I would like to get the value of a tag in an xml file, the problem is
: that, his structure is not <item>value</item> but is:

: <Cube>
: - <Cube time="somevalue">
: <Cube rate="the value i want to get" />
: <Cube rate="the value i want to get" />
: <Cube rate="the value i want to get" />
: and so on.....

: So, i have two questions, how do i get the values of the 3rd "<Cube>"
: when it is inside the tags and not ouside? and how do I choose the
: right one, having three of them?

In php 4, I use the xml parser that comes with php. The xml parser is
going to call a function that you have to write, and which you have to
register before the parsing starts.

e.g.
$xml_parser = xml_parser_create();
xml_set_element_handler( $xml_parser, "startElement", "endElement");

You need to provide functions called startElement and endElement. The last
question is how to get the third tag. To do that you need to count the
tags as you find them. The simplist way is to use a global variable.

So, your startElement function could look something like the following at
the top


$count=0;

function startElement($parser, $name, $attrs)
{
global $count;

if ($name == 'Cube')
{
$count++;
$the_rate = $attrs['rate'];

if ($count==3)
{
die("all done, value = $the_rate\n");


(Of course you probably wouldn't use die, but it illustrates the point.)




--

This space not for rent.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация