Hi all,

I am trying to create an xml file and schema that can be oppened by a .net app. However when the app trys to read from the data set, nothing is being held. I think this may be due to an error in the creation of the xml and xsd files. I would be greatful if someone could just check them over to see if there is anything out of place. Thanks

xml file

<?xml version="1.0" encoding="ISO-8859-1"?>

<tblEmployee xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="trial.xsd">
	<employee empID="001">
		<name>Jon</name>
		<surname>Cox</surname>
		<age>31</age>
	</employee>
</tblEmployee>

xsd file

<?xml version="1.0"?>
<xs:schema xmlns:xs="">
	
       <xs:element name="tblEmployee">
                <xs:complexType>
                       <xs:sequence>  
                         <xs:element name="employee">
                           <xs:complexType>         
	             <xs:sequence>
		<xs:element name="name" type="xs:string"/>
		<xs:element name="surname" type="xs:string"/>
		<xs:element name="age" type="xs:integer"/>
	             </xs:sequence>
	             <xs:attribute name="empID" type="xs:string" use="required"/>
	         </xs:complexType>
	     </xs:element>
	</xs:sequence>
       </xs:complexType>
   </xs:element>

</xs:schema>

Dani AI

Generated

Good catch by — that kind of namespace typo will break schema parsing. Beyond that, a couple of other common issues will leave a DataSet empty even after the XML and XSD look "right":

  • Namespace alignment: if the XML instance uses a default namespace, the XSD must declare a matching targetNamespace (and you will often want elementFormDefault="qualified") so the schema actually describes those names. If you prefer not to use namespaces, remove the default namespace from the instance instead.
  • xsi:schemaLocation usage: the schemaLocation attribute must pair a namespace URI with a schema location (namespace followed by filename), otherwise a parser may not be able to locate the schema.
  • How .NET reads schema/data: load the schema into the DataSet explicitly, or tell ReadXml to read the schema. Doing so prevents subtle mismatches.

Example loading patterns in C#:

var ds = new System.Data.DataSet();
ds.ReadXmlSchema("trial.xsd");
ds.ReadXml("trial.xml");

// or let ReadXml infer the schema
var ds2 = new System.Data.DataSet();
ds2.ReadXml("trial.xml", System.Data.XmlReadMode.ReadSchema);

Additional checks: validate the XSD with an XML tool or Visual Studio, confirm the XML file encoding matches its declaration, and ensure element/attribute types in the schema match the instance content. Microsoft docs on DataSet XML I/O are useful for the exact overloads and modes: DataSet.ReadXml documentation.

Recommended Answers

All 2 Replies

Member Avatar for Member #344710

Everything is correct, except you have a typo: <xs:schema xmlns:xs=""> (one too many 'w's in the schema namespace declaration; should be 'www.w3.org').

ok ty for your reply. It really was a newbi error :S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.