<...">

Insert node in xml using php

I want to insert node text and create an element in xml using php like

XML

<?xml version="1.0"?>
<employees>
  <employee>
    <name>Albert</name>
    <age>34</age>
    <salary>$10000</salary>
  </employee>
  <employee>
    <name>Claud</name>
    <age>20</age>
    <salary>$2000</salary>
  </employee>
</employees>

I want to insert data for another employee using php.

NewBie Relationship

+3
source share
2 answers
<?php 
$xml = simplexml_load_file('clients.xml');
$employee = $xml->addChild('employee');
$employee->addChild('name', 'Claud');
$employee->addChild('age', '20');
$employee->addChild('salary', 'This is all about the people who make it work.');

file_put_contents('clients.xml', $xml->asXML());
+14
source

See the DOMDocument documentation . There are examples for parsing and modifying XML.

+1
source

Source: https://habr.com/ru/post/1720974/


All Articles