Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent xsd generated class to be named "NewDataSet"?

I am creating a class library containing several datasets that are generated from client xml files.

I drag example xml files into VStudio and create .xsd file, add them to the project and sets tool to MSDataSetGenerator and then (after getting the first build error) found out that all the generated classes are called NewDataSet. I avoid build errors by setting tool namespace in the properties dialog of the xsd file. But application code that consumes multiple datasets becomes ugly because you can't use "using" without "NewDataSet" becoming ambiguous. Besides, the class name "NewDataSet" is not really useful.

Is there any way to override/affect the naming of the generated class?

like image 856
Tormod Avatar asked Dec 18 '25 09:12

Tormod


2 Answers

I have seen this and resolved it like this:

add this to your schema tag ... "xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"

So for example the first two lines of your xsd might look like:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

Your xsd likely wraps everything in an element, whose name is what you're intending the class name to be... so do this:

<xs:element name="YOUR_CLASSNAME" msdata:IsDataSet="true">

That's roughly what I did to make it work.

like image 80
DAG Avatar answered Dec 21 '25 03:12

DAG


You can change the name of the generate class by setting the id attribute of the schema element.

enter image description here

like image 23
Sam Rueby Avatar answered Dec 21 '25 03:12

Sam Rueby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!