...

View Full Version : XML getting a value



icklechurch
12-13-2010, 02:26 PM
Hi,

I've not really worked with XML and PHP before and am having what is probably a very simple problem.

I have the following code:


object(SimpleXMLElement)[69]
public 'p' =>
array
0 => string ' SEQ ' (length=5)
1 => string ' BQ? BIWOW ' (length=11)
2 => string ' see amm accunmulafed, ' (length=23)
3 => string ' Scotland will see snow accumulated, ' (length=37)
4 => string ' and whilst we will seek rain ' (length=30)
5 => string ' showers across western Wales and ' (length=34)
6 => string ' England, most is away from the ' (length=32)
7 => string ' coastal fringes and it is a fine ' (length=34)
8 => string ' day. Mainly like winds. ' (length=25)


Which is taken from the following xml doc:


<div xml:lang="en">
<p begin="0.08"> SEQ </p>
<p begin="0.20"> BQ? BIWOW </p>
<p begin="1.84"> see amm accunmulafed, </p>
<p begin="2.84"> Scotland will see snow accumulated, </p>
<p begin="2.84"> and whilst we will seek rain </p>
<p begin="4.16"> showers across western Wales and </p>
<p begin="6.44"> England, most is away from the </p>

How do I get that into a php array where I have the begin value too?

I've tried some tutorials but they make no sense :(

Fou-Lu
12-13-2010, 02:41 PM
I don't do any work involving the simpleXMLElement's, but the API specifies that the attributes are not shown while examining the object (print_r and var_dump for examples).
Check this link for retrieving all the attributes from a SimpleXMLElement:
http://php.ca/manual/en/simplexmlelement.attributes.php

Alternatively, the DOM allows you to specify which attribute you want to target (while getting a full list is more complicated than the simplexml approach).

ngen
12-14-2010, 05:33 PM
$abc=new XMLReader();
$abc->XML($xml);
$abc->read();
$abc->read();
$temparr=array();
while($abc->next("p"))
$temparr[$abc->getAttribute("begin")]=$abc->readString();


what about trying XMLReader



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum