在php中加载xml时出错(不是绝对的) [英] Error loading xml in php (not absolute)

查看:98
本文介绍了在php中加载xml时出错(不是绝对的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用多个名称空间声明来加载XML文档 我的php是:

I am trying tom load an XML document with multiple namespace declarations My php is:

<?php 
$doc = new DOMDocument('1.0','UTF-8'); 
$doc->load( 'UBLCatalog.xml' ); 

$Items = $doc->getElementsByTagNameNS( "UBLCommonAggregateComponents","Item" ); 
foreach( $Items as $Item ) 
{ 
 $descriptions = $Item->getElementsByTagNameNS( "UBLCommonBasicComponents","Description" ); 
 $description = $descriptions->item(0)->nodeValue;  

 echo "<b>$description\n</b><br>"; 
 } 
?> 

错误是:

xmlns:URI UBLCatalogDocument在以下位置不是绝对的 文件:///C:/wamp/www/XMLExperiments/UBLCatalog.xml,

xmlns: URI UBLCatalogDocument is not absolute in file:///C:/wamp/www/XMLExperiments/UBLCatalog.xml,

我正在获取输出,但是错误很烦人.

I am getting output, but the error is annoying.

逐字错误是:注意:DOMDocument :: load()[domdocument.load]:xmlns:URI UBLCatalogDocument在文件:///C:/wamp/www/XMLExperiments/UBLCatalog.xml中不是绝对的,行:第3行的C:\ wamp \ www \ XMLExperiments \ ItemsXml.php中的4

The verbatim error is: Notice: DOMDocument::load() [domdocument.load]: xmlns: URI UBLCatalogDocument is not absolute in file:///C:/wamp/www/XMLExperiments/UBLCatalog.xml, line: 4 in C:\wamp\www\XMLExperiments\ItemsXml.php on line 3

而且,如果我删除默认的名称空间(xmlns ="UBLCatalogDocument"),错误就会消失

And, if I remove the default namespace (xmlns="UBLCatalogDocument") the error goes away

推荐答案

PHP XML扩展(DOM,XMLReader,SimpleXml等)

PHP XML extenstions (DOM, XMLReader, SimpleXml etc.) use libxml library to parse XML files.

此错误的原因是, libxml期望在xmlns属性中使用绝对URL(即xmlns="http://example.com/some-unique-url"),但仅获取文本(xmlns="UBLCatalogDocument").

The reason of this error is that libxml expects absolute URL in xmlns atttibute (i.e. xmlns="http://example.com/some-unique-url"), but gets only text (xmlns="UBLCatalogDocument").

libxml网页:

名称空间值必须是绝对URL,但URL不必 必须指向网络上的任何现有资源.

The namespace value has to be an absolute URL, but the URL doesn't have to point to any existing resource on the Web.

因此,如有可能,请将您的xmlns属性更改为某个绝对URL.

So if it's possible, change your xmlns attribute to some absolute URL.

这篇关于在php中加载xml时出错(不是绝对的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆