Total members 11889 |It is currently Fri Mar 29, 2024 1:20 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Add a new node element to XML file from a php
Code:
<?php
     $tel_node 
= null;
     $doc = xmldocfile ('contact.xml');
     $contact_node = $doc->root ();
     $kids = $contact_node->children ();

     while ($node = array_shift ($kids)) {
          if (($node->type == XML_ELEMENT_NODE) && ($node->tagname == 'personal')) {
               $tel_node =& $node;
               break;
          }
     }
     if ($tel_node == null){
          die ("Couldn't locate 'personal' node.");
     }
     $work_node = $tel_node->new_child ('work', '6666');
   
     print 
("<pre>\n");
     print (htmlspecialchars ($doc->dumpmem ()));
     print ("</pre>\n");
?>


here is the xml example file :
Code:
<!--
<
contact id="43956">
     <personal>
          <name>
               <first>J</first>
               <middle>J</middle>
               <last>J</last>
          </name>
          <title>Manager</title>
          <employer>National</employer>
          <dob>1971-12-22</dob>
     </personal>
</
contact>
-->
            




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Adding a New Node to contact.xml
 Beginner needs help- simple 'mail_to' contact form in PHP     -  
 adding abbreviations to your html     -  
 Need automatic adding to catalogs     -  
 adding padding to your text     -  
 Adding lighting to a solid sphere     -  
 adding a button with link in skymiles_red     -  
 Adding watermark to all images in a folder     -  
 adding caption to table in html     -  
 Adding vertical array in java     -  
 adding an xmlns attribute xith jaxb     -  



Topic Tags

PHP XML






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com