如何将属性添加到xml节点?

时间:2014-01-23 11:42:42

标签: php xml

我在php中生成以下xml。

PHP代码: -

header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo "<Response>";
echo "<Dial>";
echo  $client_no;
echo "</Dial>";
echo "<Say>The call failed or the remote party hung up. Goodbye.</Say>";
echo "</Response>";

输出: -

<Response>
  <Dial>919880022477</Dial>
  <Say>
      The call failed or the remote party hung up. Goodbye.
  </Say>
</Response>

现在我想将属性添加到Dial节点。 类似的东西: -

<Dial callerId="jitu">919880022477</Dial>

1 个答案:

答案 0 :(得分:1)

试试这个

echo "<Dial callerID='jitu'>";