【发布时间】:2016-03-22 03:43:40
【问题描述】:
我在 localhost 中尝试了一个 xml 文档,但它显示错误为“XML Parsing Error: not well-formed 地点:http://localhost/xml/user.php ,第 4 行,第 906 列:
我搜索了 xml 文件结构中的任何错误,例如缺少结束标记。但我找不到。
但是当我在没有 php 标签的浏览器中运行这个 xml 文件(不删除任何元素 - 原始 xml 文件)时。它运行良好,并在浏览器中显示树结构。
我的代码如下;
<?php
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo "<xs:schema
xmlns='http://www.google.com'
xmlns:xs='http://www.google.com'
xs:schemaLocation='http://www.google.com'>";
echo " <xs:user>";
echo " <xs:element1 name='username'>";
echo " <xs:simpleType>";
echo " <xs:restriction base='xs:string'>";
echo " <xs:minLength value='5'/>";
echo " <xs:maxLength value='12'/>";
echo " <xs:pattern value='[a-zA-Z0-9]'/>";
echo " <xs:whiteSpace value='collapse'/>";
echo " </xs:restriction>";
echo " </xs:simpleType>";
echo " </xs:element1>";
echo " <xs:element2 name='password'>";
echo " <xs:simpleType>";
echo " <xs:restrictions base='xs:string'>";
echo " <xs:pattern value='[a-zA-Z0-9]'/>";
echo " <xs:minLength value='8'/>";
echo " </xs:restrictions>";
echo " </xs:simpleType>";
echo " </xs:element2>";
echo " <xs:element3 name='fullname' type='xs:string'/>";
echo " <xs:element4 name='initials'>";
echo " <xs:simpleType>";
echo " <xs:restrictions base='xs:string'>";
echo " <xs:pattern value='[A-Z][A-Z][A-Z]'/>";
echo " <xs:whiteSpace value='collapse'/>";
echo " </xs:restrictions>";
echo " </xs:simpleType>";
echo " </xs:element4>";
echo " <xs:element5 name='gender'>";
echo " <xs:simpleType>";
echo " <xs:restrictions base='xs:string>";
echo " <xs:pattern value='male|female'/>";
echo " </xs:restrictions>";
echo " </xs:simpleType>";
echo " </xs:element5>";
echo " </xs:user>";
echo "</xs:schema>";
?>
【问题讨论】: