我正在使用DOMi(http://domi.sourceforge.net)从数组创建XML。
但我不知道如何在这些XML中创建属性(在数组中,因此这些属性出现在XML中)。我怎样才能构造这些数组,以便在转换后得到一些带有属性的标签?
谢谢!
答案 0 :(得分:2)
查看源代码,显然您将第二个参数"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;
}
//...
}