Reputation: 91
I tried a xml document in localhost, but it shows error as "XML Parsing Error: not well-formed Location: http://localhost/xml/user.php , Line Number 4, Column 906:
I searched for any errors in the structure of the xml file, such as a missing end-tags. but i couldn't find.
But when I ran this xml file (without removing any element - original xml file) in the browser without php tags. it works well and shows the tree structure in the browser.
my codes are as follows;
<?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>";
?>
Upvotes: 0
Views: 955
Reputation: 2112
You have missed a single quote here <xs:restrictions base='xs:string'>
and also remove line breaks from line number 4
Here is your 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>";
?>
Upvotes: 2