douyuanqia665858 2018-06-08 19:03
浏览 33

Php simplexml在两个xml文档之间查找/替换

First question posted here. I've tried to research this but either I'm not defining my question properly or I'm missing something obvious, so I'm bringing this to the group brain.

I'm writing a web app for a non-profit theatre I work for, using PHP. In this app, I use SimpleXML to pull down two XML documents from another location - one is a list of orders with price numbers, the other is a list of prices with price names.

What I'm trying to do, as simply and elegantly as possible, is iterate through the order document, find each price number ("price_id", a seven-digit number), go to the other document which also has those seven-digit numbers as well as a corresponding price name (price_name, which is"regular", "senior", "group", "student", "passholder", etc), and either - whichever is simpler - replace the number in the first document with the name from the second, or add an element following the number which has the corresponding price name, so that each patron shows up in the order document with a human-understandable price name instead of just a seven digit number that makes our box office staff go "huh?"

Psuedocode (from memory...):

    $orders = simplexml_get_file(https://the-url-of-the-xml-order-document);
    $prices = simplexml_get_file(https://the-url-of-the-xml-price-document);
    foreach($orders->item->price_id as $price)
     {
     //...here inlies my question, but what I'd like to do is...
    $price = $prices->item->(the price_name that corresponds to the price_id); 
    //...but I haven't found a simple way to do this, or really any way, 
    //based on my searches, but I know there has to be some way.
    }

Thank you!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度