Because of project needs, I need to use php to modify the value on xml. Use DOMdocument to do it.
The code is as follows
$xmlpatch ='http://www.*****.com/vr/wtest/vtour/tour.xml';
$xml = simplexml_load_file($url);
$doc = new DOMDocument();
$doc -> formatOutput = true;
if($doc -> load($xmlpatch)) {
$root = $doc -> documentElement;
$elm = $root -> getElementsByTagName('scene');
$hotspot = $elm[1] ->getElementsByTagName('hotspot');
$hotspot[0] ->setAttribute('videourl',$videourl1);
$hotspot[1] ->setAttribute('onclick',$videourl2);
$doc->save($xmlpatch);
}
The code should be fine. The problem is that I originally wrote a relative path in $xmlpatch. Because I used the local environment package, there is no problem.
But the environment php files and xml on the server are placed across domains, so I changed them to absolute paths. But I found that the script failed. Someone online suggested using simplexml to do it. But I can indeed read it after experimenting, but I can't find a function to modify attributes on w3cschool.
Please help me~ I would be very grateful~ Can you tell me how to modify the attributes of simplexml, or how to read the domdocument using the url.
First use curl to read the information of the xml file, and then use DOMdocument or simplexml to process it.