我試圖讀取XML文件,該文件是讀取XML:無法通過使用simplexml_load_file在PHP
<?xml version="1.0" encoding="UTF-8"?>
<!-- UNCLASSIFIED -->
<!-- Built from ANZLIC MET Template ISO 19139 2009-02-18 -->
-<gmd:MD_Metadata xsi:schemaLocation="http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/gmd.xsd http://www.opengis.net/gml http://www.isotc211.org/2005/gml/gml.xsd http://www.w3.org/1999/xlink http://www.isotc211.org/2005/xlink/xlinks.xsd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd">
<!--METValidation=False-->
-<gmd:fileIdentifier> <gco:CharacterString>D09C1546-5CB8-49AE-B717-E74FF3499F57</gco:CharacterString> </gmd:fileIdentifier>
...
...
...
我用$xml = simplexml_load_file($_FILES["file"]["tmp_name"]);
,但我有問題,命名空間和冒號!
有人能幫助我如何閱讀這個XML嗎?
乾杯, 阿拉什
你說你 「與命名空間和冒號問題」,但你不要告訴我們這是什麼問題。有很多關於此問題的現有問題,但我不確定將其標記爲重複。關鍵函數是' - > children($ ns)',' - > attributes($ ns)',並且(如果你想使用XPath)'''''registerXPathNamespace()''。 – IMSoP
問題是,只要我使用「$ xml = simplexml_load_file($ _ FILES [」file「] [」tmp_name「]);」它在讀取XML文件時返回錯誤,而在讀取另一個沒有名稱空間的XML時,它很好!我不知道如何在讀取文件時發生錯誤時使用registerXPathNamespace()! – Ark
你看到的實際錯誤信息是什麼?即使您不明白錯誤消息的含義,您也應該複製確切的消息,以便其他人可以看到您遇到的問題。 – IMSoP