How to reference local XSD from XML file?
Asked Answered
H

1

5

I want to write a simple XML file with a custom xsd file located in the same local directory on my computer. I don't understand the necessary syntax at the beginning of the files (I have googled but XSD tutorials seem to focus on the element definitions rather than the xsd:schema).

My sys_params.xsd begins:

<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">

<xsd:element     name="shipOrder" type="order"/>

My sys_params.xml begins:

<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com sys_params.xsd"

<orderperson>John Smith</orderperson>

My XML reports this validation error on the xml:

Error schema document 'sys_params.xsd' has different target namespace from the one specified in instance document 'http://www.w3schools.com'

No doubt my code is quite wrong but I need some help to correct it please.

Homey answered 8/7, 2016 at 10:8 Comment(0)
T
11

Change

xsi:schemaLocation="http://www.w3schools.com sys_params.xsd"

to

xsi:noNamespaceSchemaLocation="sys_params.xsd"

because your XML is not in a namespace.

See also:

Tufts answered 8/7, 2016 at 12:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.