简体   繁体   English

XML和PHP简单问题

[英]XML & PHP Simple Question

I need to add in a $person into the area were you add a value into addChild ,So it add's the value fo $person it into my xml file 我需要在该区域中添加一个$ person,如果您将一个值添加到addChild中,那么它将$ person的值添加到我的xml文件中

$person->addChild('first_name', $person); $ person-> addChild('first_name',$ person);

I know this is wrong but could some one explain why ? 我知道这是错误的,但是有人可以解释为什么吗?

Thanks 谢谢

Second argument of SimpleXMLElement::addChild is only used for string values, like: SimpleXMLElement :: addChild的第二个参数仅用于字符串值,例如:

<first_name>Oliver</first_name>

If you have subelements in the element, you have to create them without specifying a string value (a subelement created will be returned by addChild ), and then populate with attributes, values, and sub-elements of their own. 如果元素中包含子元素,则必须在不指定字符串值的情况下创建它们(创建的子元素将由addChild返回),然后使用其自身的属性,值和子元素填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM