【发布时间】:2018-01-05 18:38:58
【问题描述】:
我尝试用这个 php 函数打印文件 affresco.xml 的内容:
<?php $xml=simplexml_load_file("http://localhost/chiesa/affresco.xml") or
die("Error: Cannot create object");
echo $xml->title . "<br>";
echo $xml->description . "<br>";
?>
但它没有打印任何东西。在我尝试了相同的功能但我从 xml 标签中删除了“dc”之后,它就起作用了。这是 affresco.xml:
<?xml version="1.0"?>
<metadata
xmlns="http://localhost/chiesa/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://localhost/chiesa/
http://localhost/chiesa/schema.xsd"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<title>
UKOLN
</title>
<dc:description>
UKOLN is a national focus of expertise in digital information
management. It provides policy, research and awareness services
to the UK library, information and cultural heritage communities.
UKOLN is based at the University of Bath.
</dc:description>
</metadata>
如何在不删除“dc”标签的情况下打印?
【问题讨论】:
-
dc是 xml 文件中的命名空间。 -
感谢您的回答。我知道“dc”是一个命名空间,但我不明白如何使用我的 php 函数从 xml 打印值。