0

当我与之通信的站点因维护而关闭时,我收到以下 XML 消息,我需要检测并检索错误消息“xxxxxxxxx.com 在我们执行常规系统维护时暂时不可用”。希望有人能帮忙!

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 
              ) 
            ) 
          ) 
        ) 
      ) 
    ) 
  ) 
) 
4

1 回答 1

0

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

但是,请注意,SimpleXML 仅在您的输入是有效的 XML 时才有效,这是 HTML,不能保证是有效的 XML。

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

于 2012-10-22T14:54:40.273 回答