XML Schema, hide .xsd file from the schemaLocation attribute

563 Views Asked by At

I would like to ask If there is any option of validating my xml without specifying the .xsd location in the "xsi:schemaLocation=" attribute.

e.g my xml file.

<?xml version="1.0" ?>
<test:XMLFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:test="http://test/"
            xsi:schemaLocation="http://test/" {relative/absolute path}/Test.xsd">
  <Data> TEST </Data>
</test:XMLFile>

I want to hide the .xsd location for security reasons so is there any other option to hide the xsi:schemaLocation="http://test/" {relative/absolute path}/Test.xsd ?

Maybe embed the .xsd into a lib or even in the parser?

Cheers,

J.

1

There are 1 best solutions below

1
On

Yes, absolutely. There is no requirement to identify the schema in xsi:schemaLocation, and many people consider it bad practice. (Apart from anything else, if you need to validate, that implies you don't trust the document content, so why should you trust it to point to the right schema?)

Unfortunately you've said nothing about your processing environment, but I think most validators will provide both a command line interface and an API that allows you to specify the source document and schema independently.

The main case where xsi:schemaLocation can be useful is when you're using an authoring tool to validate as you type.