0

这就是我现在正在使用的:

//variable assignment that create strings from text input element
$xmlUsernameStr = $xmlDetail->userString();

//this is the function used above
public function userString(){
    return $user;//this is the variable that holds username on input element
}

//assignments in php script 
$sxml = new SimpleXmlElement(file_get_contents('details.xml'));
$xmlDetailTag = new SimpleXMLElement('<detail></detail>');  

//details.xml contains:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<details>
<detail></detail>
</details>

//create another child 'user' within parent 'detail' 
$aUserTag = $sxml->detail->addChild('user');

那么,如果我所拥有的是正确的,那么实际写入 xml 的内容是什么?

4

1 回答 1

0
$xml = simplexml_load_file('details.xml');
$xml->addChild('details')->addChild('detail', $xmlUsernameStr );
file_put_contents('details.xml', $xml->asXML());
于 2012-10-04T20:02:43.653 回答