BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
PHP XML
PHP SimpleXML Function Save
PHP SimpleXML Function load_string
PHP SimpleXML Function Load_File
PHP SimpleXML Function LoadXML
PHP SimpleXML Function Load
PHP SimpleXML Function Open_File
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
 
 

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 :349

 

PHP SimpleXML: Function New_Doc

PHP Version: PHP4 >= 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_new_doc() function creates an XML document from the scratch and returns it.

Example:

<?php

$doc = domxml_new_doc("1.0");

$root = $doc->create_element("root");

$root = $doc->append_child($root);

$child1 = $doc->create_element("child1");

$child1 = $root->append_child($child1);

$child2= $doc->create_element("child2");

$child2= $head->append_child($child2);

$textchild2 = $doc->create_text_node("Text Element in Child2");

$ textchild2 = $title->append_child($textchild2);

$doc->dump_file("/tmp/test.xml", false, true);

?>

How it Works:

I have created a small xml document using functions available in PHP4.

$doc = domxml_new_doc("1.0");

In the above line of code, I created a new XML DOM object using domxml_new_doc(). This created a new DOM object.

$root = $doc->create_element("root");

After I created a new DOM object, I created an root element with name root.

$root = $doc->append_child($root);

I appended the root element to the DOM document, which I have created in the first step.

$child1 = $doc->create_element("child1");

$child1 = $root->append_child($child1);

$child2= $doc->create_element("child2");

$child2= $head->append_child($child2);

$textchild2 = $doc->create_text_node("Text Element in Child2");

$ textchild2 = $title->append_child($textchild2);

Then I created some child elements and text node and appended in appropriate place.

$doc->dump_file("/tmp/test.xml", false, true);

After I created the DOM document, then I saved it as an xml file with name test.xml. I used dump_file() function to store as a file.

Warning:

This function is EXPERIMENTAL. The behavior of this function, the name of this function, and anything else documented about this function may change without notice in a future release of PHP. Use this function at your own risk.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

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



answering service
help desk services
swimming pool contractor
help desk
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    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