php simplexml set attribute

Tuesday, November 3, 2015

the simple example xml file is



<body id="" doi="100000">
</body>


php



  $feed = file_get_contents('/../files/schema.xml');
$datasetxml = simplexml_load_string($feed);
$datasetxml->body['id']=2;
$datasetxml->body['doi']="200000";
echo $datasetxml->asXML();


I want to change it as id=2 and doi=200000 but after reset value the result is wrong and only can see in the web page source?



 <?xml version="1.0"?>
<body id="1" doi="100000">

<body id="2" doi="200000"/></body>

0 comments:

Post a Comment