simplexml_load_file结果。我需要帮助从此返回的XML消息中提取错误消息

时间:2012-10-21 13:04:48

标签: php file load simplexml

当我正在与之通信的站点停止维护时,我收到以下XML消息,我需要检测并检索错误消息“xxxxxxxxx.com在执行常规系统维护时暂时不可用”。希望someonme可以提供帮助!

SimpleXMLElement Object (
  [head] => SimpleXMLElement Object ( 
    [meta] => SimpleXMLElement Object (
      [@attributes] => Array ( 
        [http-equiv] => Content-Type 
        [content] => text/html; charset=UTF-8 
      ) 
    ) 
    [title] => Updates In Progress 
    [link] => SimpleXMLElement Object ( 
      [@attributes] => Array ( 
        [href] => style/style.css 
        [rel] => stylesheet 
        [type] => text/css 
      ) 
    ) 
  ) 
  [body] => SimpleXMLElement Object (
    [div] => SimpleXMLElement Object (
      [@attributes] => Array (
        [id] => container 
      ) 
      [div] => Array (
        [0] => SimpleXMLElement Object ( 
          [@attributes] => Array ( 
            [id] => header 
          ) 
          [img] => SimpleXMLElement Object ( 
            [@attributes] => Array ( 
              [src] => images/top_banner.jpg 
              [alt] => xxx Freight | Updates In Progress 
            ) 
          ) 
        ) 
        [1] => SimpleXMLElement Object ( 
          [@attributes] => Array ( 
            [id] => wrapper 
          ) 
          [div] => Array ( 
            [0] => SimpleXMLElement Object ( 
              [@attributes] => Array ( 
                [id] => leftCol 
              ) 
              [p] => Array ( 
                [0] => SimpleXMLElement Object ( 
                  [strong] => SYSTEM MAINTENANCE 
                ) 
                [1] => xxxxxx.com is temporarily unavailable while we perform regular system maintenance. 
                [2] => We're sorry for the inconvenience. Please check back soon. 
              ) 
            ) 
            [1] => SimpleXMLElement Object ( 
              [@attributes] => Array ( 
                [id] => rightCol 
              ) 
              [p] => For immediate assistance, please contact Customer Service at 1-800-610-6500. 
            ) 
            [2] => SimpleXMLElement Object ( 
              [@attributes] => Array ( 
                [class] => clearfloat 
              ) 
            ) 
          ) 
        ) 
      ) 
    ) 
  ) 
) 

1 个答案:

答案 0 :(得分:0)

尝试使用simpexml_tree()输出SimpleXML对象。它给出的输出应该提示您找到所需节点所需的操作。

但是,请注意,只有当您的输入是有效的XML时,SimpleXML才会起作用,而且这是HTML,不能保证它是有效的XML。

如果可能,请检查从服务器返回的HTTP状态(例如,使用CURL CURLOPT_HEADERFUNCTION选项),并查看服务器在关闭时是否返回标准5xx状态。 (通常为500或503)。