Php 我需要在另一个标记中读取标记的XML属性
我试图独自解决它,但已经过去了几个星期,我无法解决 我有这样一个XML:Php 我需要在另一个标记中读取标记的XML属性,php,xml,Php,Xml,我试图独自解决它,但已经过去了几个星期,我无法解决 我有这样一个XML: <?xml version="1.0" encoding="UTF-8"?> <clothes> <clothe premium="no" id="1"> <list gender="0" style="11" name="Jacket"/> <list gender="1" style="12" name="Jacket"/> </cl
<?xml version="1.0" encoding="UTF-8"?>
<clothes>
<clothe premium="no" id="1">
<list gender="0" style="11" name="Jacket"/>
<list gender="1" style="12" name="Jacket"/>
</clothe>
<clothe premium="yes" id="2">
<list gender="0" style="13" name="Pants"/>
<list gender="1" style="14" name="Pants"/>
</clothe>
</clothes>
DOM节点是树的成员,并且完全知道它们的父节点/子节点。所以搜索
Cloth
元素:
$clothes = $this->element->getElementsByTagName('clothe');
foreach($clothes as $clothe) {
$premium = $clothe->getAttribute('premium');
$lists = $clothe->getElementsByTagName('list'); // get all `<list>` under the current node
foreach($lists as $list ) {
$gender = $list->getAttribute('gender');
...
}
}
$cloth=$this->element->getElementsByTagName('cloth');
foreach($Cloth作为$Cloth){
$premium=$Cloth->getAttribute('premium');
$lists=$Cloth->getElementsByTagName('list');//获取当前节点下的所有``
foreach($lists作为$list列出){
$gender=$list->getAttribute('gender');
...
}
}
一旦您有了
元素,请在下面搜索所有
。感谢Marc B回答我,并从你的角度看你的代码是正确的。。。但我不知道为什么它对我不起作用:/I我使用这个公共函数将另一个页面插入到mysql表中我在这里得到的数据。。。无论如何,如果其他人有另一个代码来帮助我尝试,我会很感激的!
$clothes = $this->element->getElementsByTagName('clothe');
foreach($clothes as $clothe) {
$premium = $clothe->getAttribute('premium');
$lists = $clothe->getElementsByTagName('list'); // get all `<list>` under the current node
foreach($lists as $list ) {
$gender = $list->getAttribute('gender');
...
}
}