I created XSD using Visual StudioXML Tools. And I use following C# code to validate XML and facing this error.
Error
The elem
You are very close. In your XSD, simply replace,
with
and your XSD will no longer have that error, and your XML will be valid against your XSD.
XSDs can be composed via xs:import and xs:include. In both cases, the location of the referenced XSD has to be specified with a required schemaLocation
attribute, which was missing in OP's original XSD. By adding xs:import/@schemaLocation
as shown above, the error is eliminated.
When you switched to use a local XSD, you made a mistake in your xs:import
:
Change
to
(You were following an example for @xsi:schemaLocation
in XML documents which has namespace-location pairs; xs:import/@schemaLocation
is different.)
So my question is how to fix it because in edit mode XML is valid 100%?
Perhaps this is the disconnect. Editing an XML file in Visual Studio does not automatically validate it against an XSD. You need to do that in code or via a validating XML editor such Oxygen XML Editor or XML Spy.
Also, your C# validation code may have issues. See Validating an XML against referenced XSD in C#