dsimib1625 2011-12-07 11:01
浏览 6

将xml对象的部分保存为对象

I created an xml file that stores some information for me. Now I want to get elements that meet some conditions.

At the moment this looks like this:

Function getElements($xmlObject, $name){

    foreach($xmlObject->feature as $feature){

    if(stristr($feature->path, $name))){    
     array_push($aSubFeatures, $feature);

    }
    }

    return $obj;
}

But I'd prefer getting an object as a return value. I used simpleXML for getting the xml file as an object.

I also tried using DOM (creating new DOMDocument and tried to append the gotten feature element objects) but without reasonable result.

Would deleting all not matching parts of the xml a solution? Did not found a way to delete special elements...

Thanks for your help

  • 写回答

1条回答 默认 最新

  • duanmengsuo9302 2011-12-07 14:30
    关注

    For appending an element of a current existing DOMDocument into a new DOMDocument you have to call $newdom->importNode($nodeInOldDOM). You cannot do a regular appendChild of a node from another document.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退