使用XSLT将XML转换为SQL

使用XSLT将XML转换为SQL

问题描述:

for reasons beyond my control, I will get an XML file, and an XSLT file that can convert the XML file to either SQL code or to an error.

Lets just assume for now that we can trust the one providing the XML file not to include dangerous constructs in the XML...

I do not even know if I should use SimpleXML, XMLWriter, DOMDocument or something else. Also, should I use XSLTProcessor or something else?

What is the best way to implement this in PHP?

Thanks,

由于我无法控制的原因,我将获得一个XML文件,以及一个可以将XML文件转换为XML文件的XSLT文件 无论是SQL代码还是错误。 p>

让我们暂时假设我们可以信任提供XML文件的文件,不要在XML中包含危险的构造...... p> \ n

我甚至不知道我是否应该使用SimpleXML,XMLWriter,DOMDocument或其他东西。 另外,我应该使用XSLTProcessor还是别的什么? p>

什么是最好的 在PHP中实现这个的方法? p>

谢谢, p> div>

If I've understood your question, and xmldata and stylesheet are provided, you can simply transform it like this:

$data = new DOMDocument();
$data->loadXML('<yourxmldata />';

$stylesheet = new DOMDocument();
$stylesheet->loadXML('<yourxslstylesheet/>');

$processor = new XSLTProcessor(); 
$processor->importStylesheet($stylesheet);
var_dump($processor->transformToXML($data));