XSD: The attribute type is missing - c#

I am trying to use XSD on a XSD schema generated by trang. It is giving me the following error:
>xsd examcard.xsd /nologo /classes
Schema validation warning: The 'http://www.w3.org/2001/XMLSchema-instance:type' attribute is not declared. Line 33, position 12.
[...]
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
Error: Error generating classes for schema 'examcard'.
- The attribute type is missing.
If you would like more help, please type "xsd /?".
What does this error means ? How should I include the type type for XSD to work ?
For reference examcard.xsd is:
<?xml version="1.0" encoding="UTF-8"?>
[...]
<xs:import namespace="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="xsi.xsd"/>
where xsi.xsd is:
<?xml version="1.0" encoding="UTF-8"?>
[...]
<xs:attribute name="type" type="xs:NMTOKEN"/>
And current version is:
>xsd /?
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.8.3928.0]
Full code at:
https://github.com/malaterre/ExamCard/blob/master/xsd/examcard.xsd

Related

Error while generating C# code from xsd file - The attribute href is missing

I am trying to create C# code from xsd file using XML Schema Definition Tool (Xsd.exe). But I am getting following error:
Schema validation warning: The 'http://www.w3.org/1999/xlink:href' attribute is not declared. Line 12, position 13.
Warning: Schema could not be validated. Class generation may fail or may produce incorrect results.
Error: Error generating classes for schema 'test'.
- The attribute href is missing.
xsd file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xl="http://www.w3.org/1999/xlink"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="">
<xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="http://www.w3.org/1999/xlink.xsd"/>
<xs:element name="Image">
<xs:complexType>
<xs:attribute ref="xl:href" xmlns:xl="http://www.w3.org/1999/xlink"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Using the following command for generating file:
xsd.exe test.xsd /c /o:"."

Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown, however using web.config for connection

I have create a web app, but when I push it live using IIS, I get the following error
Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown.
Line 1:
<?xml version="1.0" encoding="utf-8"?>
Line 2:
<xs:schema id="test" targetNamespace="test.xsd" xmlns:mstns="http://tempuri.org/test.xsd" xmlns="http://tempuri.org/test.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
Line 3: <xs:annotation>
I have read online that it is the connection, however when I created the dataset, I used my web.config connection string as the reference point.
However when I check the XSD it is pointing to my web.config.

How to use namespaces when using XSD to validate a XML file

I am trying to understand how I can validate an XML file with an XSD.
I don't quite understand the namespaces.
If I have the code:
XmlDocument xDoc = new XmlDocument();
xDoc.Load(file.InputStream);
xDoc.Schemas.Add("http://www.w3.org/2001/XMLSchema-instance", #"C:MyXSD.xsd");
ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler);
xDoc.Validate(eventHandler);
I get the Error:
"The target namespace of an attribute declaration, whether local or global, must not match http://www.w3.org/2001/XMLSchema-instance."
What should I be setting the namespace to when I add the schema to the xDoc?
I have an xml like this:
<?xml version="1.0"?>
<rootNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
// My Nodes
</rootNode>
and I created an XSD from that XML.
<?xml version="1.0" encoding="Windows-1252"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:element name="rootNode">
// My Nodes
</xsd:element>
</xs:schema>
In your scenario you can just pass null as the namespace to Schemas.Add, as you are not actually using namespaces, i.e. your XML document does not use a namespace (which would be specified either with the xmlns attribute or the use of a namespace prefix).
For more information on namespaces please see http://www.w3schools.com/xml/xml_namespaces.asp.
Note that http://www.w3.org/2001/XMLSchema-instance is a namespace used to define schema attributes that relates only to the schema infrastructure and not your specific XML schema.

how to reference xsd file from xml

1) pls.xsd file
I have included pls.xsd in xml.xsd in same folder
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Externals changed by QTAssistant (http://www.paschidev.com) -->
<!--
This is a draft schema for the XML language defined in the
Pronunciation Lexicon Specification
(latest version at <http://www.w3.org/TR/pronunciation-lexicon/>)
At the time of writing, the specification as well as this schema are
subject to change, and no guarantee is made on their accuracy or the fact
that they are in sync.
Last modified: $Date: 2007/12/11 12:08:40 $
Copyright รป 2006 World Wide Web Consortium, (Massachusetts Institute
of Technology, ERCIM, Keio University). All Rights Reserved. See
http://www.w3.org/Consortium/Legal/.
-->
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:p="http://www.w3.org/2005/01/pronunciation-lexicon"
targetNamespace="http://www.w3.org/2005/01/pronunciation-lexicon"
elementFormDefault="qualified" version="1.0">
<xs:annotation>
<xs:documentation>Importing dependent namespaces</xs:documentation>
</xs:annotation>
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd" />
...
</xs:schema>
2)My XML file
from this file i am referencing pls.xsd
<?xml version="1.0" encoding="utf-8"?>
<lexicon version="1.0"
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
file://C:/xsdforproject/pls.xsd"
alphabet="x-microsoft-ups" xml:lang="en-IN">
<lexeme>
</lexeme>
</lexicon>
I have above two codes these giving me an errors in both my XML and in my pls.xsd file,
an error has occurred while opening external "DTD" file:///C:/xsdforproject/XMLSchema.dtd': Could not find file 'C:\xsdforproject\XMLSchema.dtd
I am using "Visual Studio 2010".
How to resolve this issue?
It would appear that something you're using is referencing XMLSchema.dtd, so have you tried downloading it and placing it in your xsdforproject folder?
http://www.w3.org/2009/XMLSchema/XMLSchema.dtd

NHibernate.Envers: Configuration by NHibernate core xml

My goal is to configure NHibernate.Envers by a configuration file. As far as I understod the documentation, it should be easily possible by adding a property entry in the NHibernate Core xml file.
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernate.Test">
....
<property name="nhibernate.envers.audit_table_suffix">_history</property>
</session-factory>
</hibernate-configuration>
But this leads to an Exception:
The 'name' attribute is invalid - The value 'nhibernate.envers.audit_table_suffix' is invalid according to its datatype 'String' - The Enumeration constraint failed.
I do understand the exception, NHibernate core checks for valid content in the name attribute. How can I set a NHibernate.Envers property?
The same property works when I set it by code:
cfg = new Configuration();
cfg.Configure("NHibernate.cfg.xml");
// NHibernate.Envers Configuration
cfg.SetProperty("nhibernate.envers.audit_table_suffix", "_history");
Unfortunately the documentation is wrong. You cannot put this in your NH Core configuration because NH Core will do schema validation on your xml (and is unaware of the envers properties).
I will update Envers docs shortly.

Categories