sort xml document

I have the below code. I want to sort by the tag name Date. Can someone help me to get this done?




$xmlDoc1 = new DOMDocument();
$xmlDoc1->preserveWhiteSpace = false;
$xmlDoc1->formatOutput = true;
$xmlDoc1->loadXML($response->GetEventInfoResult->any); 


$dataset1 = $xmlDoc1->getElementsByTagName( "Table" );
foreach( $dataset1 as $row1 )
{
 
    $xmlEvents = $row1->getElementsByTagName( "Event" );
    $xmlEvent = $xmlEvents->item(0)->nodeValue;
 
    $xmlDates = $row1->getElementsByTagName( "Date" );
    $xmlDate = $xmlDates->item(0)->nodeValue;
    $xmlDate = explode("T",$xmlDate);
    $xmlDate = $xmlDate[0];
    $xmlDate = date("n/j/y", strtotime($xmlDate));

Open in new window

LVL 1
JPERKS1985Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:

$xmlDoc1 = new DOMDocument();
$xmlDoc1->preserveWhiteSpace = false;
$xmlDoc1->formatOutput = true;
$xmlDoc1->loadXML($response->GetEventInfoResult->any); 


$dataset1 = $xmlDoc1->getElementsByTagName( "Table" );

$result=array();
foreach( $dataset1 as $row1 )
{
 
    $xmlEvents = $row1->getElementsByTagName( "Event" );
    $xmlEvent = $xmlEvents->item(0)->nodeValue;
 
    $xmlDates = $row1->getElementsByTagName( "Date" );
    $xmlDate = $xmlDates->item(0)->nodeValue;
    $xmlDate = explode("T",$xmlDate);
    $xmlDate = $xmlDate[0];
    $xmlDate = date("n/j/y", strtotime($xmlDate));

   
   $result[ strtotime($xmlDate) ] = array("event"=>$xmlEvent, "date"=> $xmlDate);
}

sort( $result );
print_r($result);

Open in new window

0
JPERKS1985Author Commented:
This is my output,


Array ( [0] => Array ( [event] => Cats (7:00 PM) [date] => 4/13/10 ) ) Array ( [0] => Array ( [event] => Cats (7:30 PM) [date] => 4/14/10 ) ) Array ( [0] => Array ( [event] => Cats (7:30 PM) [date] => 4/15/10 ) ) Array ( [0] => Array ( [event] => Cats (8:00 PM) [date] => 4/16/10 ) ) Array ( [0] => Array ( [event] => Boston Bruins vs Carolina Hurricanes [date] => 4/10/10 ) ) Array ( [0] => Array ( [event] => Boston Celtics vs Washington Wizards [date] => 4/9/10 ) ) Array ( [0] => Array ( [event] => Boston Celtics vs Milwaukee Bucks [date] => 4/14/10 ) ) Array ( [0] => Array ( [event] => Joe Bonamassa [date] => 4/16/10 ) ) Array ( [0] => Array ( [event] => Boston Blazers vs Minnesota Swarm [date] => 4/10/10 ) ) Array ( [0] => Array ( [event] => Boston Red Sox vs Tampa Bay Rays [date] => 4/16/10 ) ) Array ( [0] => Array ( [event] => Alvin Ailey American Dance Theatre [date] => 4/9/10 ) ) Array ( [0] => Array ( [event] => Coppelia [date] => 4/9/10 ) ) Array ( [0] => Array ( [event] => Coppelia [date] => 4/10/10 ) ) Array ( [0] => Array ( [event] => Coppelia [date] => 4/11/10 ) ) Array ( [0] => Array ( [event] => Coppelia [date] => 4/15/10 ) ) Array ( [0] => Array ( [event] => Coppelia [date] => 4/16/10 ) ) Array ( [0] => Array ( [event] => Coppelia (Matinee) [date] => 4/10/10 ) ) Array ( [0] => Array ( [event] => Smuckers Stars On Ice [date] => 4/11/10 ) ) Array ( [0] => Array ( [event] => Phantom Gourmet Wine and Food Phest [date] => 4/10/10 ) ) Array ( [0] => Array ( [event] => Roberto Carlos [date] => 4/14/10 ) )

i'm not sure why it doesn't work.
0
JPERKS1985Author Commented:
Also multiple events have the same date if that matters.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

hieloCommented:

$xmlDoc1 = new DOMDocument();
$xmlDoc1->preserveWhiteSpace = false;
$xmlDoc1->formatOutput = true;
$xmlDoc1->loadXML($response->GetEventInfoResult->any); 


$dataset1 = $xmlDoc1->getElementsByTagName( "Table" );

$result=array();
foreach( $dataset1 as $row1 )
{
 
    $xmlEvents = $row1->getElementsByTagName( "Event" );
    $xmlEvent = $xmlEvents->item(0)->nodeValue;
 
    $xmlDates = $row1->getElementsByTagName( "Date" );
    $xmlDate = $xmlDates->item(0)->nodeValue;
    $stamp=date('Y-m-d H:i:s strtotime($xmlDate));
    $xmlDate = explode("T",$xmlDate);
    $xmlDate = $xmlDate[0];
    $xmlDate = date("n/j/y", strtotime($xmlDate));

   
   $result[ ] = array("event"=>$xmlEvent, "date"=> $xmlDate, "sortKey"=>$stamp);
}
function cmp($a, $b)
{
    if ($a["sortKey"] == $b["sortKey"]) {
        return 0;
    }
    return ($a["sortKey"] < $b["sortKey"]) ? -1 : 1;
}

usort( $result,"cmp");
print_r($result);

Open in new window

0
JPERKS1985Author Commented:
It prints the first item that takes place and not the rest now.
0
JPERKS1985Author Commented:
Heres my full code.
try {
//Get Geo Events
$User = "";
$Password = "";
$Domain = "";


$client = new SoapClient("https://xmlfeed.eventprocess.com/Ticketsxml.asmx?WSDL");

$result=array();

//Get two weeks out
$Start = date('Y-m-d');
$End = date("Y-m-d", strtotime(date("Y-m-d", strtotime($Start)) . " +1 week"));

$paramSearchEvents = array('UserName' => $User, 'Password' => $Password, 
        'DomainName' => $Domain, 'Event' => '', 'Venue' => '', 
        'StartDate' => $Start, 'EndDate' => $End, 'City' => $UserCity, 'State' => $UserState,
         'bWithTickets' => 'false', 'bVerbose' => 'true');

$searchEventsresponse = $client->SearchEvents($paramSearchEvents); 

//var_dump($searchEventsresponse);

$xmlDoc = new DOMDocument();
$xmlDoc->preserveWhiteSpace = false;
$xmlDoc->formatOutput = true;
$xmlDoc->loadXML($searchEventsresponse->SearchEventsResult->any); 

/*
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item)
{
    print $item->nodeName . " = " . $item->nodeValue . "<br />";
}
*/




$dataset = $xmlDoc->getElementsByTagName( "Table" );
foreach( $dataset as $row) if ($intCount++ < 20) //Limit to 20 events.
{
    $xmlEventIDs = $row->getElementsByTagName( "EventID" );
    $xmlEventID = $xmlEventIDs->item(0)->nodeValue;
 
   


    //Second request gets event specific information.


	$paramGetEventInfo = array('UserName' => $User, 'Password' => $Password, 
        'DomainName' => $Domain, 'EventID' => $xmlEventID);

	$client = new SoapClient("https://xmlfeed.eventprocess.com/Ticketsxml.asmx?WSDL");


    $response = $client->GetEventInfo($paramGetEventInfo);



$xmlDoc1 = new DOMDocument();
$xmlDoc1->preserveWhiteSpace = false;
$xmlDoc1->formatOutput = true;
$xmlDoc1->loadXML($response->GetEventInfoResult->any); 



$dataset1 = $xmlDoc1->getElementsByTagName( "Table" );
foreach( $dataset1 as $row1 )
{
 
    $xmlEvents = $row1->getElementsByTagName( "Event" );
    $xmlEvent = $xmlEvents->item(0)->nodeValue;
 
    $xmlDates = $row1->getElementsByTagName( "Date" );
    $xmlDate = $xmlDates->item(0)->nodeValue;
    $stamp=date("Y-m-d H:i:s", strtotime($xmlDate));

    $xmlDate = explode("T",$xmlDate);
    $xmlDate = $xmlDate[0];
    $xmlDate = date("n/j/y", strtotime($xmlDate));

   
    $ShortDate = date("n/j", strtotime($xmlDate));





    $xmlTimes = $row1->getElementsByTagName( "Time" );
    $xmlTime = $xmlTimes->item(0)->nodeValue;

    $xmlTime = strtotime($xmlTime);
   
    $xmlVenues = $row1->getElementsByTagName( "VenueID" );
    $xmlVenue = $xmlVenues->item(0)->nodeValue;

    	//Pull venue name
   	$paramGetVenueInfo = array('UserName' => $User, 'Password' => $Password, 
        'DomainName' => $Domain, 'VenueID' => $xmlVenue);

	$client = new SoapClient("https://xmlfeed.eventprocess.com/Ticketsxml.asmx?WSDL");


    	$response = $client->GetVenueInfo($paramGetVenueInfo);

	$xmlDoc = new DOMDocument();
	$xmlDoc->preserveWhiteSpace = false;
	$xmlDoc->formatOutput = true;
	$xmlDoc->loadXML($response->GetVenueInfoResult->any); 
	$datasetvenue = $xmlDoc->getElementsByTagName( "Table" );

	foreach( $datasetvenue as $rowvenue )
	{
	$xmlVenueNames = $rowvenue->getElementsByTagName( "Venue" );
    	$xmlVenueName = $xmlVenueNames->item(0)->nodeValue;
	
		$pos = strpos($xmlVenueName, '(');
		if ($pos == true) {
		$xmlVenueNameExplode = explode("(", $xmlVenueName);
		$xmlVenueName = $xmlVenueNameExplode[0];
		}

	}




   	   $result[] = array("event"=>$xmlEvent, "date"=> $xmlDate, "sortKey"=>$stamp);




	


}


function cmp($a, $b)
{
    if ($a["sortKey"] == $b["sortKey"]) {
        return 0;
    }
    return ($a["sortKey"] < $b["sortKey"]) ? -1 : 1;
}

usort( $result,"cmp");
print_r($result);

Open in new window

0
hieloCommented:
try the attached code. It that doesn't work, post a sample of your xml
<?php
//Get Geo Events
$User = "";
$Password = "";
$Domain = "";


$client = new SoapClient("https://xmlfeed.eventprocess.com/Ticketsxml.asmx?WSDL");

$result=array();

//Get two weeks out
$Start = date('Y-m-d');
$End = date("Y-m-d", strtotime(date("Y-m-d", strtotime($Start)) . " +1 week"));

$paramSearchEvents = array(	'UserName' => $User
						, 'Password' => $Password
						,'DomainName' => $Domain
						,'Event' => ''
						,'Venue' => ''
						,'StartDate' => $Start
						,'EndDate' => $End
						,'City' => $UserCity
						,'State' => $UserState
						,'bWithTickets' => 'false'
						, 'bVerbose' => 'true'
					);

$searchEventsresponse = $client->SearchEvents($paramSearchEvents); 

//var_dump($searchEventsresponse);

$xmlDoc = new DOMDocument();
$xmlDoc->preserveWhiteSpace = false;
$xmlDoc->formatOutput = true;
$xmlDoc->loadXML($searchEventsresponse->SearchEventsResult->any); 

/*
$x = $xmlDoc->documentElement;
foreach ($x->childNodes AS $item)
{
    print $item->nodeName . " = " . $item->nodeValue . "<br />";
}
*/

$dataset = $xmlDoc->getElementsByTagName( "Table" );

foreach( $dataset as $row)
{
	if ($intCount++ < 20) //Limit to 20 events.
	{
		$xmlEventIDs = $row->getElementsByTagName( "EventID" );
		$xmlEventID = $xmlEventIDs->item(0)->nodeValue;

		//Second request gets event specific information.
		$paramGetEventInfo = array('UserName' => $User
								, 'Password' => $Password
								,'DomainName' => $Domain
								, 'EventID' => $xmlEventID
							);

		$client = new SoapClient("https://xmlfeed.eventprocess.com/Ticketsxml.asmx?WSDL");
		$response = $client->GetEventInfo($paramGetEventInfo);
		$xmlDoc1 = new DOMDocument();
		$xmlDoc1->preserveWhiteSpace = false;
		$xmlDoc1->formatOutput = true;
		$xmlDoc1->loadXML($response->GetEventInfoResult->any); 

		$dataset1 = $xmlDoc1->getElementsByTagName( "Table" );
		foreach( $dataset1 as $row1 )
		{
			$xmlEvents = $row1->getElementsByTagName( "Event" );
			$xmlEvent = $xmlEvents->item(0)->nodeValue;
 
			$xmlDates = $row1->getElementsByTagName( "Date" );
			$xmlDate = $xmlDates->item(0)->nodeValue;
			$stamp=date("Y-m-d H:i:s", strtotime($xmlDate));

			$xmlDate = explode("T",$xmlDate);
			$xmlDate = $xmlDate[0];
			$xmlDate = date("n/j/y", strtotime($xmlDate));
			$ShortDate = date("n/j", strtotime($xmlDate));
			$xmlTimes = $row1->getElementsByTagName( "Time" );
			$xmlTime = $xmlTimes->item(0)->nodeValue;
			$xmlTime = strtotime($xmlTime);
   
			$xmlVenues = $row1->getElementsByTagName( "VenueID" );
			$xmlVenue = $xmlVenues->item(0)->nodeValue;

			//Pull venue name
			$paramGetVenueInfo = array('UserName' => $User
									, 'Password' => $Password
									,'DomainName' => $Domain
									, 'VenueID' => $xmlVenue
								);

			$client = new SoapClient("https://xmlfeed.eventprocess.com/Ticketsxml.asmx?WSDL");
			$response = $client->GetVenueInfo($paramGetVenueInfo);
			$xmlDoc = new DOMDocument();
			$xmlDoc->preserveWhiteSpace = false;
			$xmlDoc->formatOutput = true;
			$xmlDoc->loadXML($response->GetVenueInfoResult->any); 
			$datasetvenue = $xmlDoc->getElementsByTagName( "Table" );

			foreach( $datasetvenue as $rowvenue )
			{
				$xmlVenueNames = $rowvenue->getElementsByTagName( "Venue" );
				$xmlVenueName = $xmlVenueNames->item(0)->nodeValue;
        
				$pos = strpos($xmlVenueName, '(');
				if ($pos == true) 
				{
					$xmlVenueNameExplode = explode("(", $xmlVenueName);
					$xmlVenueName = $xmlVenueNameExplode[0];
				}
			}
			$result[] = array("event"=>$xmlEvent, "date"=> $xmlDate, "sortKey"=>$stamp);
		}
	}
}


function cmp($a, $b)
{
    if ($a["sortKey"] == $b["sortKey"])
    {
        return 0;
    }
    return ($a["sortKey"] < $b["sortKey"]) ? -1 : 1;
}

usort( $result,"cmp");
print_r($result);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JPERKS1985Author Commented:
Thanks for all your help I know it was a mess to work with!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.