【发布时间】:2011-03-12 01:15:52
【问题描述】:
我正在使用 DOMi (http://domi.sourceforge.net) 从数组创建 XML。
但我不知道如何在这些 XML 中创建属性(在数组中,因此这些属性出现在 XML 中)。如何构造这些数组,以便在转换后获得一些带有属性的标签?
谢谢!
【问题讨论】:
-
如果你知道另一种方法,不用DOMi,你也可以回答!
我正在使用 DOMi (http://domi.sourceforge.net) 从数组创建 XML。
但我不知道如何在这些 XML 中创建属性(在数组中,因此这些属性出现在 XML 中)。如何构造这些数组,以便在转换后获得一些带有属性的标签?
谢谢!
【问题讨论】:
查看源代码,显然您将第二个参数"attributes" 传递给attachToXml:
public function attachToXml($data, $prefix, &$parentNode = false) {
if(!$parentNode) {
$parentNode = &$this->mainNode;
}
// i don't like how this is done, but i can't see an easy alternative
// that is clean. if the prefix is attributes, instead of creating
// a node, just put all of the data onto the parent node as attributes
if(strtolower($prefix) == 'attributes') {
// set all of the attributes onto the node
foreach($data as $key=>$val)
$parentNode->setAttribute($key, $val);
$node = &$parentNode;
}
//...
}
【讨论】: