- https://pear.php.net/package/XML_Serializer
- https://stackoverflow.com/questions/856833/is-there-any-way-to-convert-json-to-xml-in-php
- https://www.sitepoint.com/xml-php-pear-xml_serializer/
安装
pear install XML_Serializer
使用
```php <?php
function json2xml($json) {
require_once 'XML/Serializer.php';$serializer_options = ['addDecl' => true,'addDoctype' => true,'doctype' => ['id' => 'pubmed api','uri' => 'http://39.106.135.106/pubmed/api/',],'encoding' => 'UTF-8','indent' => ' ','rootName' => 'result','mode' => 'simplexml',];$Serializer = &new XML_Serializer($serializer_options);$status = $Serializer->serialize($json);if (PEAR::isError($status)) {die($status->getMessage());}header('Content-type: text/xml');echo $Serializer->getSerializedData();
}
// $data = … json2xml($data); ```
