Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php XML节点作为Smarty变量_Php_Xml_Smarty_Domdocument - Fatal编程技术网

Php XML节点作为Smarty变量

Php XML节点作为Smarty变量,php,xml,smarty,domdocument,Php,Xml,Smarty,Domdocument,我必须用PHP编写一个时事通讯shipping hub。DB架构(我无法更改)的构建方式如下: <?php // foreach loop is started here to count through a number of database entries // that explains the $i. Just adjust that to your needs // Get DOMDocument here and validate with XSD Schema //

我必须用PHP编写一个时事通讯shipping hub。DB架构(我无法更改)的构建方式如下:

<?php 

// foreach loop is started here to count through a number of database entries
// that explains the $i. Just adjust that to your needs

// Get DOMDocument here and validate with XSD Schema

// ...

// Get XML Elements and assign them to Smarty variables
$elements[$key][$i] = $dom->documentElement;
foreach ($elements[$key] as $element) {
  foreach ($element->childNodes as $el) {
    $tpl->assign($el->nodeName, $el->nodeValue);
    $params[$el->nodeName] = $el->nodeValue;
  }
}

?>
表:
\u data
:包含XML字符串形式的数据(包括客户名称、电子邮件地址等数据)和指向tpl表的链接。每行包含一封客户电子邮件,以及更多内容,这些内容可以从新闻稿更改为新闻稿

表:
\u tpl
:包含所有带有{$var}变量的时事通讯(HTML),这些变量应表示XML节点(及其数据,因此
value
应变为{$node},并且此变量应包含“value”)。再加上XSD模式,应该用它来验证XML字符串(我已经成功了)

问题是,XML字符串可能会因时事通讯而异,而且所有事情都必须动态发生(因为我必须编写一个Cronjob来收集所有数据,呈现邮件内容,然后发送它)。我被告知要使用Smarty,但我不知道如何(动态地)将XML节点转换为Smarty变量

如果有比使用Smarty更好的方法(str_replace不是选项),我洗耳恭听


我希望你明白我的问题。。。如果您需要进一步的信息,我很乐意提供。

我是这样想的:

<?php 

// foreach loop is started here to count through a number of database entries
// that explains the $i. Just adjust that to your needs

// Get DOMDocument here and validate with XSD Schema

// ...

// Get XML Elements and assign them to Smarty variables
$elements[$key][$i] = $dom->documentElement;
foreach ($elements[$key] as $element) {
  foreach ($element->childNodes as $el) {
    $tpl->assign($el->nodeName, $el->nodeValue);
    $params[$el->nodeName] = $el->nodeValue;
  }
}

?>
documentElement;
foreach($elements[$key]作为$element){
foreach($element->childNodes作为$el){
$tpl->assign($el->nodeName,$el->nodeValue);
$params[$el->nodeName]=$el->nodeValue;
}
}
?>

这就是它对我的作用

我明白你的问题,但不清楚你为什么不能解决它。Stackoverflow不是一个编程问题站点,而是一个编程问题站点,那么您具体的编程问题是什么呢?你的样本数据在哪里?演示具体问题的示例代码在哪里?请参阅,这可能还包含一些提示:然后请花一点时间回答您自己的问题,并在那里留下一个代码示例。请仅作为答案,而不是作为问题的编辑。