BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
PHP XML
PHP DOMElement Function hasAttribute
PHP DOMDocument Function getElementsByTagName
PHP DOMDocument Function getAttributeNS
PHP DOMDocument Function getAttributeNodeNS
PHP DOMDocument Function getAttribute
PHP DOMDocument Function createTextNode
PHP DOMDocument Function createProcessingInstruction
PHP DOMDocument Function createEntityReference
PHP DOMDocument Function createElementNS
PHP DOMDocument Function createElement
PHP DOMDocument Function createDocumentFragment
PHP DOMDocument Function createComment
PHP DOMDocument Function createCDATASection
PHP DOMDocument Function createAttributeNS
PHP DOMDocument Function createAttribute
PHP DOMCharacterData Function substringData
PHP DOMCharacterData Function replaceData
PHP DOMCharacterData Function insertData
PHP DOMCharacterData Function deleteData
PHP DOMCharacterData Function appendData
 
 

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

 

DOMDocument Function importNode

PHP Version: (No version information, might be only in CVS. I have used this function in PHP5)

DOM: W3C DOM Level 1

Description

This function creates a new Element. This method generally used to copy an element from one DOMDocument to another DOMDocument.

Usage:

objectDOMDocument->importNode ( object importedNode [, bool deep])

This function returns a copy of the node to import and associates it with the current document. DOMException is thrown if node cannot be imported.

Parameters:

importedNode – The Node you want to import to your document.

deep – This is used to tell whether you want to import node with all children or only the node it self.

Example:

The XML file, which I have used contains following data. I have stored this file in “c:/topxml_demo/php/xml_files/employee.xml” directory.

     <?xml version="1.0"?>

<employee>

     <employeename id="myId">test</employeename>

     <employeeaddress>test123</employeeaddress>

     <SSN>12343456</SSN>

     <company>TOPXML</company>

</employee>

PHP Code:

<?php

    $doc = new DomDocument;

// Load the xml file into DOMDocument

$doc->Load('C:/topxml_demo/php/xml_files/employee.xml');

//create a new DOM Document

$newDoc = new DomDocument;

// We retrieve the employee element from  docDomDocument

$employee = $doc->getElementsByTagName('employee')->item(0);

//import with all node with childrens. If you want only node then pass false.

$importedElement = $newDoc->importNode($employee,true);

//add the new imported element to the $newDocDomDocument

$newDoc->appendChild($importedElement);

//save the new DOMDocument into a file

$test = $newDoc->save("C:/topxml_demo/php/xml_files/save1.xml");

 echo "<BR><B>DOMDocument->importNode example with all childs<B>"

 ?>

Output:

This is imported with all childrens.The Content of save1.xml is

<?xml version="1.0"?>

<employee>

     <employeename id="myId">test</employeename>

     <employeeaddress>test123</employeeaddress>

     <SSN>12343456</SSN>

     <company>TOPXML</company>

     </employee>

If you want only the node then the PHP code would be

$importedElement = $newDoc->importNode($employee,false);

 and XML document would be

<?xml version="1.0"?>

<employee/>


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En
A Greate Opportunituy as a SQL Deve
An immediate job opportunity as a B

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



Information Online

swimming pool contractor
chicago web site design
teleconferencing services
Web Hosting
online fax service
Calvin klein sunglasses
answering service


    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