I have a .xsd file which I use to generate code with the xsd.exe tool from Visual Studio. Some class members are Guids and the xsd.exe tool gives 2 warnings:
Namespace 'http://microsoft.com/wsdl/types/' is not available to be referenced in this schema. Type 'http://microsoft.com/wsdl/types/:guid' is not declared.
The Guid type is recognized because the generated C# file is valid and works. Anyone knows how to get rid of those warnings?
What is the correct syntax for the XSD to be validated AND class members being generated as System.Guid?
Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.
The XML Schema definition language (XSD) enables you to define the structure and data types for XML documents. An XML Schema defines the elements, attributes, and data types that conform to the World Wide Web Consortium (W3C) XML Schema Part 1: Structures Recommendation for the XML Schema Definition Language.
An XML schema definition (XSD), is a framework document that defines the rules and constraints for XML documents. An XSD formally describes the elements in an XML document and can be used to validate the contents of the XML document to make sure that it adheres to the rules of the XSD.
Thank you all, I found how to remove the warnings.
As sysrqb said, the wsdl namespace has either been deleted or never existed. It seems that the xsd.exe tool knows the Guid definition internally, but it cannot validate the xsd schema.
As boj pointed out, the only way to validate the schema with Guids in it, is to (re)define that type in a schema. The trick here is to add the Guid type to the same "http://microsoft.com/wsdl/types" namespace. This way, the xsd.exe will do the proper association between http://microsoft.com/wsdl/types:Guid and System.Guid
I made a new xsd file for the guid type:
<?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://microsoft.com/wsdl/types/" > <xs:simpleType name="guid"> <xs:annotation> <xs:documentation xml:lang="en"> The representation of a GUID, generally the id of an element. </xs:documentation> </xs:annotation> <xs:restriction base="xs:string"> <xs:pattern value="\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}"/> </xs:restriction> </xs:simpleType> </xs:schema>
Then, I run xsd.exe with both my original xsd file and this new xsd file:
xsd.exe myschema.xsd guid.xsd /c
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With