BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
PHP XML
PHP SimpleXML Function xml_parser_create
PHP SimpleXML Create an XML Document
PHP XML RPC Function Server Call method
PHP XML RPC Parse Method Descriptions
PHP XML RPC Function ServerCreate
PHP XML RPC Function GetType
PHP XML RPC Function EncodeRequest
PHP XML RPC Function Encode
PHP XML RPC Function DecodeRequest
PHP DOMXPath Function registerNamespace
PHP DOMXPath Function query
PHP DOMText Function splitText
PHP DOMText Function isWhitespaceInElementContent
PHP DOMNode Function replaceChild
PHP DOMNode Function lookupPrefix
PHP DOMNode Function lookupNamespaceURI
PHP DOMNode Function isSupported
PHP DOMNode Function isSameNode
PHP DOMNode Function insertBefore
PHP DOMNode Function hasChildNodes
 
 

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :277

 

PHP SimpleXML: Function Open_File

PHP Version: PHP 4 >= 4.2.1

Description

PHPs DOM functions include domxml_new_doc() to create new XML documents, dmxml_open_file() to open an XML document file as a DOM object, and domxml_open_mem() to create a DOM object from an XML document already in memory. These functions return a DOM object, not a String to other common data type. When you use the PHP DOM extension functions, you typically first create a DOM document object and then manipulate it using functions that are part of the class of that object. There are a number of object classes available, and by starting with a DOMDocument object, you can then examine it and retrieve new objects reflecting XML document components such as element, attributes and so on. domxml_open_file() function creates a DOM object from XML file.

Usage:

objectdomxml_open_file ( string filename [, int mode [, array &error]])

Optional parameter mode can be used to change the behavior of this function. It was added in PHP 4.3.0. You can use one of the following constants for it: DOMXML_LOAD_PARSING (default), DOMXML_LOAD_VALIDATING or DOMXML_LOAD_RECOVERING. You can add to it also DOMXML_LOAD_DONT_KEEP_BLANKS, DOMXML_LOAD_SUBSTITUTE_ENTITIES and DOMXML_LOAD_COMPLETE_ATTRS byusing bitwise or option.

Example:

            <?php

                        echo "<p>Parsed Employee Data</p>";

                        $xmlfileName = $_POST['inputfile'];

                        $default_dir = "xml_files/";

                        $default_dir .=   $xmlfileName;

                        $myDOM = domxml_open_file($default_dir);

                        $root = $myDOM->document_element();

                        //print

                        $s = simplexml_import_dom($dom);

                        echo "Element Name";

                        echo   $s->employeename[0];

            ?>

How it Works:

            I have created a DOM object from a xml file. Ensure that the file is well formed.

            $myDOM = domxml_open_file($default_dir);

            In the above code I have created a DOM object.

           

            $root = $myDOM->document_element();

            After I created a new DOM object, I extracted the root element from the DOM object.

            Then I printed the name of the employee.

           

            $s = simplexml_import_dom($dom);

            echo "Element Name";

            echo   $s->employeename[0];

Output

<employee>

            <employeename>Test</employeename>

            <employeeaddress>Test Address</employeeaddress>

            <SSN>12345</SSN>

            <company>Test Company</company>

</employee>


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C
Sr. Software Engineer

View all Jobs (Add yours)
View all CV (Add yours)



spfxmasks
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses
conference calling


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP