Support for creating C# classes out of Schema or DTDs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am reading data out of a relational database and converting the data to XML.
I after I send this data from a web service I am reading the data using
XMLTextReader calls like the following:
if(customerReader.NodeType == XmlNodeType.Element)
if (customerReader.LocalName.Equals("COLUMN1NAME"))

I hate using the colmn names like this (or in a constant).
What I want to do is specify the structure of the XML doc wiht a Schema (or
DTD) and then generate an object model from this. The Schema would have to
match my query i.e. there needs to be easy to add the data.

I would like to call something like.
row = xmldoc.readRow();
String row.COLUMN1NAME();

Any suggestiong on how I can do this?
 
plex4r said:
I am reading data out of a relational database and converting the data to
XML.
I after I send this data from a web service I am reading the data using
XMLTextReader calls like the following:
if(customerReader.NodeType == XmlNodeType.Element)
if (customerReader.LocalName.Equals("COLUMN1NAME"))

I hate using the colmn names like this (or in a constant).
What I want to do is specify the structure of the XML doc wiht a Schema
(or
DTD) and then generate an object model from this. The Schema would have
to
match my query i.e. there needs to be easy to add the data.

I would like to call something like.
row = xmldoc.readRow();
String row.COLUMN1NAME();

Any suggestiong on how I can do this?

The .NET Framework SDK has a tool to do this:

xsd.exe
http://msdn.microsoft.com/library/d...s/html/cpconXMLSchemaDefinitionToolXsdexe.asp

David
 
Plex4r,
I suggest you consider the XSDObjectGen add-in, which can be found for
download on MSDN. This actually gives you a new project type for this in
Visual Studio .NET, and it runs rings around XSD.EXE.
Peter
 
Peter and David, thanks for the information. Either solution sounds just
like what I need. I will investigate both and see which solution works best
for me.

Regards, Bill.
 
I am using xsd.exe to create classes out of an xml file.

Can someone show me the XMLStream calls to make to populate this?. I have
the data in a String var.

System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public class NewDataSet {[
[System.Xml.Serialization.XmlElementAttribute("CustomerXMLString",
Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public NewDataSetCustomerXMLString[] Items;
}
public class NewDataSetCustomerXMLString {

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string NAME;
....
 
plex4r said:
I am using xsd.exe to create classes out of an xml file.

Can someone show me the XMLStream calls to make to populate this?. I have
the data in a String var.

System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public class NewDataSet {[
[System.Xml.Serialization.XmlElementAttribute("CustomerXMLString",
Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public NewDataSetCustomerXMLString[] Items;
}
public class NewDataSetCustomerXMLString {

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string NAME;
....

Use the XmlSerializer class.
http://msdn.microsoft.com/library/d...emxmlserializationxmlserializerclasstopic.asp

David
 
Back
Top