473,396 Members | 1,917 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,396 software developers and data experts.

how to use object as array like in simplexml

Hi,
I am new to PHP, and I'm trying to implement something similar to
SimpleXML. The following code demonstrates an example of what I'm
trying to achieve:

<?php
$xmlstr = <<<XML
<asdf>
<foo att="val1">bar1</foo>
<foo att="val2">bar2</foo>
</asdf>
XML;

$xml = new SimpleXMLElement($xmlstr);

echo $xml->foo . "<br>";
echo $xml->foo[0] . "<br>";
echo $xml->foo[1] . "<br>";
echo $xml->foo[1]["att"] . "<br>";
?>

The output of this code is:

bar1
bar1
bar2
val2

What type of object is $xml->foo and how can I create a similar
object? It can be accessed as an array (e.g. $xml->foo[1]). But
echoing it doesn't print "Array" as usual, but rather apparently calls
the __toString method of $xml->foo[0].

Thanks a lot.

-Emmett
Mar 29 '08 #1
0 1149

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

Similar topics

1
by: hwcowan | last post by:
Hello, I have started using SimpleXML and can do most things, but there are a couple of things that I can't seem to figure out. Currently, I can: 1. Open & load an XML file 2. Manually...
3
by: theboss3 | last post by:
Take, for example a typical RSS 2.0 feed (like http://lorelle.wordpress.com/feed/) and tell me how I access the tags like 'content:encoded' and 'wfw:commentRSS' using SimpleXML. I've searched far...
1
by: root | last post by:
Hi folks - hope someone can help me. Firstly, my apologies for crossposting this to alt.php (and not properly crossposting either). I have an XML file with some elements like those below ...
2
by: mandric | last post by:
Hello, Can someone please enlighten me on how to preserve the <!]> element when parsing an xml file or string with simplexml. I'm using libxml 2.6.16 and php 5.1.4. I tried a few variations,...
1
by: Andy | last post by:
Hi, I'm running in to a little issue with SimpleXML, and wondered if anyone knew if it was normal implementation for SimpleXML, or I'm not using a correct flag, or even it's a an issue that...
1
by: Chuy08 | last post by:
Currently I have the following XML document: <Programs> <Program> <ProductTypeName>30 Yr Fixed</ProductTypeName> <Rate>6.250</Rate> <APR>6.274</APR> <InvestorName>Helos</InvestorName>...
0
by: ty | last post by:
I have a script that takes a xml template then adds data into it using SimpleXMLElement. I then save it using asXML into a mysql database. On my development machine at home it works fine. ...
3
by: =?ISO-8859-1?Q?Feij=F3?= | last post by:
I've been trying to find a code or a way to create that a parse that return this to me: $html = 'loren ipsum'; $html = 'loren ipsum 2'; $html = 'path/to/a/file'; $html = 'header 1'; $html =...
5
by: KDawg44 | last post by:
Hi, Is there a way to get a multidimensional associative array with the entire result set? I would like to get a an array like this: resultsArray How can I accomplish this? Can I do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.