Jump to content

Troubles using XmlReader to get an array..


Scooby08

Recommended Posts

I have this xml:

 

<?xml version="1.0"?>
<Schedule NAME="Hockey">
<EventType ID="500">
	<Date DTEXT="Wed, Jan 13, 10">
		<Event STATUS="Open">

			<Competitor NAME="Minnesota">
				<At WHERE="Away"/>
			</Competitor>

			<Competitor NAME="St. Louis">
				<At WHERE="Home"/>
			</Competitor>

			<Time TS="1263434700000" TTEXT="9:05p EST"/>

		</Event>
	</Date>
</EventType>
</Schedule>

 

And I'm trying to get this sort of array out of it:

Array
(
    [attr] => Array
        (
            [NAME] => Hockey
        )

    [EventType] => Array
        (
            [attr] => Array
                (
                    [iD] => 500
                )

            [Date] => Array
                (
                    [attr] => Array
                        (
                            [DTEXT] => Wed, Jan 13, 10
                        )

                    [Event] => Array
                        (
                            [attr] => Array
                                (
                                    [sTATUS] => Open
                                )

                            [Competitor] => Array
                                (
                                    [0] => Array
                                        (
                                            [attr] => Array
                                                (
                                                    [NAME] => Minnesota
                                                )

                                            [At] => Array
                                                (
                                                    [attr] => Array
                                                        (
                                                            [WHERE] => Away
                                                        )

                                                )

                                        )

                                    [1] => Array
                                        (
                                            [attr] => Array
                                                (
                                                    [NAME] => St. Louis
                                                )

                                            [At] => Array
                                                (
                                                    [attr] => Array
                                                        (
                                                            [WHERE] => Home
                                                        )

                                                )

                                        )

                                )

                            [Time] => Array
                                (
                                    [attr] => Array
                                        (
                                            [TS] => 1263434700000
                                            [TTEXT] => 9:05p EST
                                        )

                                )

                        )

                )

        )

)

 

And am trying it like so:

<?php
$xml = new XMLReader();
$xml->open('test.xml');

while ($xml->read()) {
   // what to do??
}    
?>

 

Could anybody provide some assistance?? I'm really stuck at this point.. I can't even post what I have tried really because it doesn't even work..

 

Thank you!!

i dunno exactly what you are trying to achieve, but it looks like you are just wanting to find word boundaries to the LHS and RHS of an equals sign (=) in the XML and use the LHS as an array key and the RHS as the value. thought I've never used or bothered with XML so I don't know if you need that *exact* array output format. i guess the xml functions may allow you to pull data from the xml?

 

i've never really understood what xml is really good for? anyone can give me a quick overview?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.