473,406 Members | 2,371 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,406 software developers and data experts.

what is the easiest way to get a 2D array from an XML stream?

I can't quite figure out PHP's XML functions. Given an XML stream like
the one below, how do I get a 2D array?
<xml>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

</xml>
Jul 17 '05 #1
4 1755
Parse the file with preg_match_all. That'll give you a 2D array.

Uzytkownik "lawrence" <lk******@geocities.com> napisal w wiadomosci
news:da**************************@posting.google.c om...
I can't quite figure out PHP's XML functions. Given an XML stream like
the one below, how do I get a 2D array?
<xml>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

</xml>

Jul 17 '05 #2
On 19 Mar 2004 15:40:54 -0800, lk******@geocities.com (lawrence) wrote:
I can't quite figure out PHP's XML functions. Given an XML stream like
the one below, how do I get a 2D array?
<xml>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

<entry>
<weblogHeadline>
Saddam found in Iraq
</weblogHeadline>
<weblogContent>
Military forces score a breakthrough today
</weblogContent>
</entry>

</xml>


http://uk.php.net/xml_parse_into_struct perhaps.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3
On Sat, 20 Mar 2004 10:35:12 -0500, "Chung Leong" <ch***********@hotmail.com>
wrote:
Uzytkownik "lawrence" <lk******@geocities.com> napisal w wiadomosci
news:da**************************@posting.google. com...
I can't quite figure out PHP's XML functions. Given an XML stream like
the one below, how do I get a 2D array?


Parse the file with preg_match_all. That'll give you a 2D array.


But a 2D array of what? You cannot parse XML with a single regular expression,
they aren't capable of storing enough state information to act as an
SGML/HTML/XML parser.

To parse XML, use an XML parser.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #4
A 2D array of a XML file of a specific schema as noted in the original post.
RegExp is perfectly capable of parsing that.

Uzytkownik "Andy Hassall" <an**@andyh.co.uk> napisal w wiadomosci
news:50********************************@4ax.com...
On Sat, 20 Mar 2004 10:35:12 -0500, "Chung Leong" <ch***********@hotmail.com> wrote:
Uzytkownik "lawrence" <lk******@geocities.com> napisal w wiadomosci
news:da**************************@posting.google. com...
I can't quite figure out PHP's XML functions. Given an XML stream like
the one below, how do I get a 2D array?
Parse the file with preg_match_all. That'll give you a 2D array.


But a 2D array of what? You cannot parse XML with a single regular

expression, they aren't capable of storing enough state information to act as an
SGML/HTML/XML parser.

To parse XML, use an XML parser.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

Jul 17 '05 #5

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

Similar topics

5
by: Christian Seberino | last post by:
In c extension what is easiest way to build a (PyObject) list from an array of doubles? I don't think I can do "return Py_BuildValue(...) to make a list from an array can I??? How else can I...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
13
by: jesper | last post by:
Hello, I have to load strings from a datbase and put them into an array. I get them by packets of 100 strings of 50 characters. Then I should do something like that : StringArray But x can be...
8
by: xmail123 | last post by:
Hi, As was pointed out whatever you return from a WebMethod needs to be serializable to SOAP. An ArrayList is not serializable. I will be needing to return other data types from web methods. ...
2
by: siddiq | last post by:
1)I want to play a file when someone dials my phone no 2) also to detect the digit pressed by the caller can i get any idea how to do this in VB.net using TAPI 3 MSDN provides code snippet of...
5
by: sherifffruitfly | last post by:
Hi, I'm just learning cpp, and the exercise I'm working on is basically as follows: 1) Create a struct type with 4 members (char, char, char, int). 2) Create an array of, say 3 instances of...
29
by: calvert4rent | last post by:
I need to some sort of data type that will hold a listing of ID's and their counts/frequency. As I do some processing I get an ID back which I need to store and keep an accurate count for how many...
2
by: shahiz | last post by:
basically im having null pointer exception //read an inputstream is = new DataInputStream(new FileInputStream("test.mpg")); loadBytes(is); //pass it as a datasource for the player public...
9
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've an optimization question for you all really quick. I have a stream that I am reading some bytes. At times, the stream can contain a small amount of bytes such as 50...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.