SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    montreal
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml parsing into php

    Hi,

    This is my first time doing anything for xml, I'm a php guy, but I have a problem that I have to solve using xml, so any help would be appreciated.

    How would I take information from a page and put in on my page.

    There's this page http://www.di.fm/partners/xml/playlists.xml that has information I need. All i want from that is the TRACKTITLE from the first channel (VocalTrance). I want to put that info into my PHP page

    Like I said, I have never worked with xml, but I do know enough PHP (i think...)

    Thank you

  2. #2
    SitePoint Member
    Join Date
    Sep 2004
    Location
    michigan
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might find the following Sitepoint article useful:
    http://www.sitepoint.com/article/php...arsing-rss-1-0

    Maybe check these tutorials as well:
    http://www.zend.com/zend/art/parsing.php
    http://www.codehelp.co.uk/php/xmlparse1.php

    The PHP manual also has a section dedicated to XML:
    http://us2.php.net/xml

    Source: http://www.google.com/search?q=php+p...en-US:official

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2004
    Location
    montreal
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok vexon, i read up on it and found a sample script that works good (i tried it) but (and i feel bad asking you) I can't configure it to what I need. I honestly don't think it'll take a long time (or else i wouldnt ask). Can you change the code so that it shows what i need it to show?

    Only if you don't mind

    here's the code

    PHP Code:

    $compiled_langs 
    = array();
    $interprt_langs = array();
    $flag '';
    $count 0;

    function 
    opening_element($parser$element$attributes) {
        
    // opening XML element callback function

        
    global $flag;

        if (
    $element == 'languages')
            
    $flag $attributes['type'];

    }

    function 
    closing_element($parser$element) {
        
    // closing XML element callback function

        
    global $flag;

        if (
    $element == 'languages')
            
    $flag '';
    }

    function 
    character_data($parser$data) {
        
    // callback function for character data

        
    global $flag;

        if (
    $flag == 'compiled') {
            global 
    $compiled_langs;
            
    $compiled_langs[] = $data;
        }

        if (
    $flag == 'interpreted') {
            global 
    $interprt_langs;
            
    $interprt_langs[] = $data;
        }

    }

    $parser xml_parser_create();
    xml_parser_set_option($parserXML_OPTION_CASE_FOLDINGfalse);
    xml_set_element_handler($parser'opening_element''closing_element');
    xml_set_character_data_handler($parser'character_data');

    $document file('http://www.di.fm/partners/xml/playlists.xml');

    foreach (
    $document as $line) {
        
    xml_parse($parser$line);
    }

    xml_parser_free($parser);

    printf("The following compiled languages were found...\n");
    foreach (
    $compiled_langs as $name) {
        
    $count++;
        
    printf("%' 3d. %s\n"$count$name);
    }

    $count 0;
    printf("\nThe following interpreted languages were found...\n");
    foreach (
    $interprt_langs as $name) {
        
    $count++;
        
    printf("%' 3d. %s\n"$count$name);

    as you can see http://www.di.fm/partners/xml/playlists.xml that's the xml page i am using, all i want on my php page is to show this:

    Channel: Vocal Trance
    Track: (whatever the track is)

    Vocal Trance is the first channel on that list, it's the only one i need.

    Again, thank you for your time


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •