PHP xml_parse_into_struct() Function

|  | Search W3Schools : |

HOME | HTML | CSS | XML | JAVASCRIPT | ASP | PHP | SQL | MORE... |  | References | Examples | Forum | About

ADVERTISEMENTS XML Certification Download XML editor Custom Programming |  |

Table of contents

PHP Basic
PHP HOME
PHP Intro
PHP Install
PHP Syntax
PHP Variables
PHP String
PHP Operators
PHP If...Else
PHP Switch
PHP Arrays
PHP Looping
PHP Functions
PHP Forms
PHP $_GET
PHP $_POST
PHP Advanced
PHP Date
PHP Include
PHP File
PHP File Upload
PHP Cookies
PHP Sessions
PHP E-mail
PHP Secure E-mail
PHP Error
PHP Exception
PHP Filter
PHP Database
MySQL Introduction
MySQL Connect
MySQL Create
MySQL Insert
MySQL Select
MySQL Where
MySQL Order By
MySQL Update
MySQL Delete
PHP ODBC
PHP XML
XML Expat Parser
XML DOM
XML SimpleXML
PHP and AJAX
AJAX Introduction
XMLHttpRequest
AJAX Suggest
AJAX XML
AJAX Database
AJAX responseXML
AJAX Live Search
AJAX RSS Reader
AJAX Poll
PHP Reference
PHP Array
PHP Calendar
PHP Date
PHP Directory
PHP Error
PHP Filesystem
PHP Filter
PHP FTP
PHP HTTP
PHP Libxml
PHP Mail
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Quiz
PHP Quiz
PHP Exam

Selected Reading

Web Statistics
Web Glossary
Web Hosting
Web Quality
W3Schools Tutorials
W3Schools Forum
Helping W3Schools

# PHP xml_parse_into_struct() Function

Complete PHP XML Reference

## Definition and Usage

The xml_parse_into_struct() function parses XML data into an array.

This function parses the XML data into 2 arrays:

- Value array - containing the data from the parsed XML
- Index array - containing pointers to the location of the values in the Value array

This function returns 1 on success, or 0 on failure.

## Syntax

    xml_parse_into_struct(parser,xml,value_arr,index_arr)

Parameter | Description
--- | ---
parser | Required. Specifies XML parser to use
xml | Required. Specifies XML data to parse
value_arr | Required. Specifies the target array for the XML data
index_arr | Optional. Specifies the target array for index data

## Tips and Notes

Note: The xml_parse_into_struct() function returns 1 for success and 0 for failure. This is not the same as TRUE and FALSE.

## Example

XML File

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <note>
    <to>Tove</to>
    <from>Jani</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
    </note>

PHP Code

    <?php
    //invalid xml file
    $xmlfile = 'test.xml';
    $xmlparser = xml_parser_create();

    // open a file and read data
    $fp = fopen($xmlfile, 'r');
    $xmldata = fread($fp, 4096);

    xml_parse_into_struct($xmlparser,$xmldata,$values);

    xml_parser_free($xmlparser);
    print_r($values);
    ?>

The output of the code above will be:

    Array
    (
    [0] => Array
      (
      [tag] => NOTE
      [type] => open
      [level] => 1
      [value] =>
      )
      [1] => Array
        (
        [tag] => TO
        [type] => complete
        [level] => 2
        [value] => Tove
        )
    [2] => Array
      (
      [tag] => NOTE
      [value] =>
      [type] => cdata
      [level] => 1
      )
      [3] => Array
        (
        [tag] => FROM
        [type] => complete
        [level] => 2
        [value] => Jani
        )
    [4] => Array
      (
      [tag] => NOTE
      [value] =>
      [type] => cdata
      [level] => 1
      )
      [5] => Array
        (
        [tag] => HEADING
        [type] => complete
        [level] => 2
        [value] => Reminder
        )
    [6] => Array
      (
      [tag] => NOTE
      [value] =>
      [type] => cdata
      [level] => 1
      )
      [7] => Array
        (
        [tag] => BODY
        [type] => complete
        [level] => 2
        [value] => Don't forget me this weekend!
        )
    [8] => Array
      (
      [tag] => NOTE
      [value] =>
      [type] => cdata
      [level] => 1
      )
    [9] => Array
      (
      [tag] => NOTE
      [type] => close
      [level] => 1
      )
    )

Complete PHP XML Reference

## Make your web applications look like a million bucks

Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.

FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc. and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our 12,000 customers and 150,000 users which include a majority of the Fortune 500 companies. And yeah, your applications could look like a million bucks by spending just $69.

So go ahead, download your copy of FusionCharts and start "wow-ing" your customers now!

WEB HOSTING
ASP.NET Shopping Cart
$15 Domain Name Registration Save $20 / year!
Buy UK Domain Names Register Domain Names
Cheap Domain Names Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting

WEB BUILDING
Website Templates Flash Templates Website Builder Internet Business Opportunity
Custom Programming
FREE Trial or Demo Web Content Manager Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates

EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification

HOME or Top of Page |  | Printer Friendly
W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy. Copyright 1999-2009 by Refsnes Data. All Rights Reserved.