1

I have a problem with my XML and XSD.

I'm trying to use the XHTML tag <img> in my schema but I can't import the XHTML schema. The error that the validator is giving to me is:

Fatal error at line 0 column 0, unsupported protocol in URL.

The next is a minimal example that replicate my problem.

This is file.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xhtml="http://www.w3.org/1999/xhtml">

<xsd:import namespace="http://www.w3.org/1999/xhtml" 
schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" />

<xsd:element name="tag" >
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element ref="xhtml:img" />    
  </xsd:sequence>  
 </xsd:complexType>
</xsd:element>
</xsd:schema>

And this file.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<tag xmlns:xsi="w3.org/2001/XMLSchema- instance" 
xmlns:xhtml="w3.org/1999/xhtml"; xsi:noNamespaceSchemaLocation="file.xsd"> 
  <xhtml:img href="http://" /> 
</tag>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Artorias
  • 11
  • 3

1 Answers1

0

You don't want to place your entire XML file in the XHTML namespace. (And xsi:noNamespaceSchemaLocation is for when there's no namespace anyway.)

So change

<file xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://www.w3.org/1999/xhtml" 
      xsi:noNamespaceSchemaLocation="file.xsd">

to

<file xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xhtml="http://www.w3.org/1999/xhtml" 
      xsi:noNamespaceSchemaLocation="file.xsd">

and then use the xhtml namespace prefix selectively on the XHTML elements only.


Update

Now that a full MCVE has been added to the question, there are numerous issues evident with your XSD and XML:

  • xmlns:xhtml="w3.org/1999/xhtml"; shouldn't end in a ;.
  • xmlns:xsi declaration is hosed in multiple ways.
  • etc.

etc.

Here's a working XSD/XML pair with the above and other issues resolved:

XML

<?xml version="1.0" encoding="UTF-8"?> 
<tag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xhtml="http://www.w3.org/1999/xhtml" 
     xsi:noNamespaceSchemaLocation="file.xsd"> 
  <xhtml:img src="http://" alt=""/> 
</tag>

XSD

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:xhtml="http://www.w3.org/1999/xhtml"
            elementFormDefault="qualified">

  <xsd:import namespace="http://www.w3.org/1999/xhtml" 
              schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" />

  <xsd:element name="tag" >
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="xhtml:img" />    
      </xsd:sequence>  
    </xsd:complexType>
  </xsd:element>
</xsd:schema>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Oh yes sorry... i'm changing theese files in any way and i forgot that. But also with this changing the validation error is the same – Artorias Jun 22 '18 at 14:00
  • It's hard to get a good solution to unstated problems. Next see the duplicate link for how to specify references to local XSDs properly. – kjhughes Jun 22 '18 at 14:07
  • The error seems to be in the import tag because when i delete him the validator says i haven't include the xhtml namespace. But with the include it says: "Fatal error at line 0 column 0, unsupported protocol in URL." – Artorias Jun 22 '18 at 14:16
  • Until you produce a **[mcve]** that reproduces the problem, tracking down the issue will take more back-and-forth than this site and my patience are willing to support. – kjhughes Jun 22 '18 at 14:41
  • Ok i've modified the answer putting the minimal example. I'm sorry but this is my first answer – Artorias Jun 22 '18 at 15:21
  • @Artorias: Does the update showing complete, working XML and XSD documents now resolve your problem? – kjhughes Jun 25 '18 at 15:15