How to parse this xml file?

Discussion in 'PHP' started by ErsinAcar, Jul 7, 2007.

  1. #1
    Hi!

    I trying to parse a xml file with this method;

    		$feed="http://www.ersinacar.com/video.xml";
    		$ch = curl_init();
    		$timeout = 0;
    		curl_setopt ($ch, CURLOPT_URL, $feed);
    		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    		$xml = curl_exec($ch);
    		curl_close($ch);
    		//echo $xml;
    preg_match_all("/<video videoId=\"(.*?)\" permalinkId=\"(.*?)\" extension=\"(.*?)\" length=\"(.*?)\" size=\"(.*?)\" fileHash=\"(.*?)\" tags=\"(.*?)\" previewHash=\"(.*?)\" previewHashLow=\"(.*?)\" highResImage=\"(.*?)\" medResImage=\"(.*?)\" username=\"(.*?)\" writerName=\"(.*?)\" directorName=\"(.*?)\" producerName=\"(.*?)\" castName=\"(.*?)\" studio=\"(.*?)\" screenFormat=\"(.*?)\" copyRightOwner=\"(.*?)\" releaseDate=\"(.*?)\" views=\"(.*?)\" rating=\"(.*?)\" numRatingVotes=\"(.*?)\" numDownloads=\"(.*?)\" numViews=\"(.*?)\" description=\"(.*?)\" title=\"(.*?)\" dateAdded=\"(.*?)\" age=\"(.*?)\" primaryCollectionPermalink=\"(.*?)\" primaryCollectionTitle=\"(.*?)\" primaryCollectionThumb=\"(.*?)\" allowEmbedding=\"(.*?)\" premium=\"(.*?)\" contentRatingId=\"(.*?)\" category=\"(.*?)\" numOfComments=\"(.*?)\">/i",$xml,$out,PREG_SET_ORDER);
    
    print_r($out);
    
    PHP:
    but it's not working. any idea?
    Thanks.
     
    ErsinAcar, Jul 7, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Tried to echo $xml but nothing appeared.

    Peace,
     
    Barti1987, Jul 7, 2007 IP
  3. ErsinAcar

    ErsinAcar Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try right click --> show source
     
    ErsinAcar, Jul 7, 2007 IP
  4. corycollier

    corycollier Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If all you're doing is parsing xml, you might try simplexml. Look it up on php.net. It's a really good library
     
    corycollier, Jul 7, 2007 IP
  5. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #5
    ansi, Jul 7, 2007 IP
  6. ErsinAcar

    ErsinAcar Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i tiried xml_parser exp. but it's not working.
    used on my xml file and result

    Array
    (
        [ok] => Array
            (
                [1] => Array
                    (
                        [1054] => Array
                            (
                                [TAGLIST] => 
    			
    	
                                [THUMBNAILLIST] => 
    			
    	
                            )
    
                        [1907] => Array
                            (
                                [TAGLIST] => 
    			
    	
                                [THUMBNAILLIST] => 
    			
    	
                            )
    
                    )
    
            )
    
    )
    
    PHP:
    it can't parse videos..
     
    ErsinAcar, Jul 7, 2007 IP
  7. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #7
    because in order to use it, you need to get rid of all of the attributes and put them in their own tags...

    
    <rsp>
    	<videos>
    		<video>
    			<title>some title</title>
    			<length>12:34</length>
    			<tags>jay cross blogs bloggers theweblogproject opensource robin good</tags>
    		</video>
    		<video>
    			<title>another title</title>
    			<length>1:34</length>
    			<tags>jay cross blogs bloggers theweblogproject opensource robin good</tags>
    		</video>
    	</videos>
    </rsp>
    
    Code (markup):
     
    ansi, Jul 7, 2007 IP
  8. ErsinAcar

    ErsinAcar Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    but this xml file is not mine getting from a video site... so i can't change anything.
     
    ErsinAcar, Jul 8, 2007 IP