473,249 Members | 1,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,249 software developers and data experts.

php & xml questions

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?

Thank you,

Stefano

Jul 17 '05 #1
3 1499
Stefano (te********@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.
Jul 17 '05 #2
U¿ytkownik "Malcolm Dew-Jones" <yf***@vtn1.victoria.tc.ca> napisa³ w
wiadomo¶ci news:42******@news.victoria.tc.ca...
The simplist way is to use a global variable.


/me thinks that better would be any static variable, but "de gustibus non
disputantum est".

To author of the topic: i'd use XPath expresion it's easy. how?

eg.
$dom=domxml_open_mem($xml);
$xpath = xpath_new_context(&$this->dom);
$result=xpath_eval($xpath,'/cube/cube/cube/@rate');
print $result[0]->value;

Jul 17 '05 #3
Stefano said the following on 10/06/2005 21:40:
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?


See the PHP XML functions, at http://www.php.net/manual/en/ref.xml.php.
Particularly xml_set_element_handler().
--
Oli
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Will | last post by:
On the subject of Data Warehouses, Data Cubes & OLAP…. I would like to speak frankly about Data Warehouses, Data Cubes and OLAP (on-line analytical processing). Has it dawned on anyone else...
19
by: Philipp Lenssen | last post by:
I don't know the English word, but I'm referring to the double-dash which is used to separate parts of a sentence. I'm using — so far. Now I saw – which is slightly shorter. Some sites use --. ...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
1
by: Sandeep | last post by:
Hi, I want to read & print a UTF-8 encoded characters stored in a file. I want to write a C program on Linux platform to achieve this. I am new to UTF-8. I will appreciate any sample...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
2
by: Jim Carlock | last post by:
http:/ / aquaticcreationsnc . com/lib/php/test.php Remove the spaces to visit the link above... The w3 validator identifies the ampersand character as the leading character for special...
4
by: drew197 | last post by:
I am a newbie. I am editing someone elses code to make it compatible with Firefox and Safari. In IE, when you click on the proper link, a block of text is shown in a nice paragraph form. But, in...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
1
by: robertmeyer1 | last post by:
Hi, I have 3 tables set up. tblQuestion, tblAnswer, tblClient. I have them linked together and have a sbf and mainform set up for data entry. The sbf links the questions and answers together. ...
2
by: Erik Scofield | last post by:
Two problems. Okay, I have been trouble shooting this for many hours, doing as much research as possible. YUI calendar control in IE 6.0: Elements show through it. Can't figure this one...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.