SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml data with php

    Hi All,
    Is it possible to load an xml data into a drop down box using php.I was able to create the xml file, but not able to parse it through php.

    Thanks in advance,

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using PHP 4 or PHP 5 ?

    If you are using PHP 5 I'd suggest you look at SimpleXML which basically parses the XML and returns it in the form of an array.
    David

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    I am using php 4 .Is there any way to do that in php 4?

    Thanks,

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found a simple example,

    http://www.kirupa.com/web/xml_php_parse_beginner.htm

    This is really a good exmple and very simple for beginners

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml parser

    Hi,
    I have a problem, i was able to ceate the xml file and parse that through php.But i wanto to display the result in a drop down box can someone modify the php script,


    This is my php code to parse the xml file,

    PHP Code:
    <?php 

    $file 
    "names.xml"

    function 
    contents($parser$data){ 
        echo 
    "".$data""


    function 
    startTag($parser$data){ 
        echo 
    ""


    function 
    endTag($parser$data){ 
        echo 
    "<br/>"


    $xml_parser xml_parser_create(); 

    xml_set_element_handler($xml_parser"startTag""endTag"); 

    xml_set_character_data_handler($xml_parser"contents"); 

    $fp fopen($file"r"); 

    $data fread($fp8000000); 

    if(!(
    xml_parse($xml_parser$datafeof($fp)))){ 
        die(
    "Error on line " xml_get_current_line_number($xml_parser)); 


    xml_parser_free($xml_parser); 

    fclose($fp); 

    ?>
    The xml will look like this,

    <List>
    <Names>Joe</Names>
    <Names>John</Names>
    <Names>Smith</Names>
    <Names>Sara</Names>
    </List>

    Can someone help me here?

    Thanks,

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Guys,
    Can someone help me here?

  7. #7
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about using the
    xml_parse_into_struct('xmlfile')
    command that way you get an array with all your values and you can then easily access your 'names' values.
    Have a go and echo out the resulting two arrays and see what results you get. You should be able to see what to do.....

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i will try this

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Gainesville, Florida
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe build a dynamic xsl file that takes the data you grab from a dynamic xml file and builds a form using <xsl:value-of select="x"/>. Haven't tried this yet but its worth a shot.

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    chennai
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am new to all these concepts, i will try these ways.
    Anyway thanks guys,


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
  •