使用php在xml中插入节点 [英] Insert node in xml using php

查看:31
本文介绍了使用php在xml中插入节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想插入文本节点并使用php在xml中创建元素例如

I want to insert text node and create element in xml using php for example

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>

我想使用 php 为另外一名员工插入数据.

I want insert Data for one more employees using php.

问候新人

推荐答案

<?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());

这篇关于使用php在xml中插入节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆