Results 1 to 5 of 5

Thread: How to use XML Parsing using PHP

  1. #1
    Join Date
    Apr 2009
    Posts
    37

    How to use XML Parsing using PHP

    I have done programming in XML parsing, but I wanted to same into an PHP, i even also know that XML language is very handy to have parsing but i have an project development requirement in PHP and because of that i had requirement in PHP environment. so if does anyone knows how to do that please help me.

    Thanks in Advance.

  2. #2
    Join Date
    Oct 2008
    Posts
    167

    Re: How to use XML Parsing using PHP

    I also have mine XML code but when we view the XML page in the browser all you see is the XML code! The PHP file using the XML parser must be tailored to one particular structure or DTD that won't do. We need to find a way to format it. There are actually many ways to do this. I prefer to use PHP to get the job done. And that is what this tutorial is all about; using PHP to parse and format an XML document. This toolkit lets you parse, but not validate, XML documents. It supports three source character encodings also provided by PHP: US-ASCII, ISO-8859-1 and UTF-8. UTF-16 is not supported.If you don't know anything about PHP then you might not want to start here. A good place to start is php.net. They have a great beginner tutorial for dealing with the basics of PHP.

  3. #3
    Join Date
    Feb 2009
    Posts
    105

    Re: How to use XML Parsing using PHP

    For our purposes, we're going to call the document example.xml.The PHP XML parser now needs two functions to be declared, one that handle the element of data and one to handle the character data within the elements.By handling mime-types and using browser detection, CodeHelp has already shown how to export XML using a PHP script. PHP can also receive XML as input - using the XML parser,XMLParser,comes in 2 flavours, one is for PHP 4 and one is for PHP 5. Both flavours are accessed through the exact same interface, so you can write code to use this parsing system and, as long as you include the right flavour of the parser file.

  4. #4
    Join Date
    Dec 2008
    Posts
    202

    Re: How to use XML Parsing using PHP

    Target encoding is done when PHP passes data to XML handler functions. When an XML parser is created, the target encoding is set to the same as the source encoding, but this may be changed at any point.SimpleXML documentation involves echoing the plot of the first movie, and below example involves echoing the plot of the movie for each movie.

    Code:
    <?php
    //Echo the plot of the first <movie>
    echo $parser->document->movie[0]->plot[0]->tagData;
    
    //Echo the plot of each <movie>
    foreach($parser->document->movie as $movie)
    {
        echo $movie->plot[0]->tagData;
    }
    ?>

  5. #5
    Join Date
    Oct 2011
    Posts
    1

    Down Re: How to use XML Parsing using PHP

    Hi,
    You may use the following code to resolve your problem..
    // initialize xml parser
    $parser = xml_parser_create();

    // User define function to start the element

    function start ($parser,$element)
    {
    switch($element)
    {
    case "NOTE":
    echo '------Note ------<br/>';
    break;

    case "TO":
    echo "To : ";
    break;

    case "FROM" :
    echo 'From : ';
    break ;

    case "SUBJECT":
    echo "Subject :";
    break ;

    case "MESSAGE":
    echo "Message :";
    break ;

    default : echo "This is default section.";
    }

    }

    // function to use at the end of element

    function stop ($parser,$element)
    {
    echo '<br/>';
    }

    // function to use when find character data

    function char($parser,$data)
    {
    echo $data ;
    }

    // specify element handler

    xml_set_element_handler($parser, "start", "stop");
    // specify data handler

    xml_set_character_data_handler($parser, "char");


    // open xml file

    $file = fopen("C://Users//Sachindra//Desktop//TestXml.xml", "r");


    // read the xml file

    while ($data = fread($file, "4000"))

    {

    xml_parse($parser,$data,feof($file)) or

    die (sprintf("XML Error: %s at line %d",xml_error_string(xml_get_error_code($parser)),xml_get_current_line_number($parser)));

    }


    // free the xml parser

    xml_parser_free($parser);
    for more information you may check out this link...

    Thanks !!!!

Similar Threads

  1. Parsing XML in Objective C
    By Sheravat in forum Software Development
    Replies: 4
    Last Post: 29-05-2010, 05:58 AM
  2. Parsing XML using MSXML
    By Arumugan in forum Software Development
    Replies: 5
    Last Post: 10-03-2010, 06:20 AM
  3. Parsing XML WebService
    By Efigenio in forum Software Development
    Replies: 4
    Last Post: 03-03-2010, 03:55 AM
  4. javafx xml parsing example
    By russ_da_buss in forum Software Development
    Replies: 3
    Last Post: 10-08-2009, 06:56 PM
  5. Parsing in C++
    By Elijah in forum Software Development
    Replies: 4
    Last Post: 20-04-2009, 11:39 PM

Tags for this Thread

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
  •  
Page generated in 1,711,676,847.24420 seconds with 17 queries