473,473 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML Serialization question using XSD.exe generated code

Hi
I have the following XML file:

================================================== =========
<?xml version="1.0" encoding="UTF-16"?>
<Policy xmlns="http://tempuri.org/richard.xsd">
<TransType />
<LOB />
<Name>
<FirstName />
<LastName />
</Name>
</Policy>
================================================== =========

I created the following XSD and CS code using xsd.exe:
================================================== =========
<?xml version="1.0" ?>
<xs:schema id="NewDataSet"
targetNamespace="http://tempuri.org/richard.xsd"
xmlns:mstns="http://tempuri.org/richard.xsd"
xmlns="http://tempuri.org/richard.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="Policy">
<xs:complexType>
<xs:sequence>
<xs:element name="TransType" type="xs:string" minOccurs="0" />
<xs:element name="LOB" type="xs:string" minOccurs="0" />
<xs:element name="Name" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string"
minOccurs="0" />
<xs:element name="LastName" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element ref="Policy" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
================================================== =========
================================================== =========
using System.Xml.Serialization;
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://tempuri.org/richard.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://tempuri.org/richard.xsd",
IsNullable=false)]
public class Policy {

/// <remarks/>
public string TransType;

/// <remarks/>
public string LOB;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Name ")]
public PolicyName[] Name;
}

/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://tempuri.org/richard.xsd")]
public class PolicyName {

/// <remarks/>
public string FirstName;

/// <remarks/>
public string LastName;
}

/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespac e="http://tempuri.org/richard.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespac e="http://tempuri.org/richard.xsd",
IsNullable=false)]
public class NewDataSet {

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("Poli cy")]
public Policy[] Items;
}
================================================== =========

My question is whether the following is the only way to fill in an
object of type Policy, or if somebody can show me a better way (the
part I'm most concerned about is the "PolicyName[]" part:

================================================== =========
Policy myPolicy = new Policy();
myPolicy.TransType = "Transaction Type";
myPolicy.LOB = "Homeowners";

PolicyName myName = new PolicyName();
myName.FirstName = "John";
myName.LastName = "Smith";

myPolicy.Name = new PolicyName[1];
myPolicy.Name[0] = myName;

XmlSerializer serializer = new XmlSerializer(typeof(Policy));

TextWriter writer = new StreamWriter("policy.xml");
serializer.Serialize(writer, myPolicy);
writer.Close();
================================================== =========

Thanks.

- Richard

Nov 29 '06 #1
0 1784

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andrewcw | last post by:
I made one C sharp class that was successful with the XSD utility in the SDK bin. However now I can't get any xml file to work with the other generated classes. The serialization always stops on...
0
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ...
0
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
0
by: eSapient | last post by:
I generated serialization/deserialization code for this schema using the xsd tool: <?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefault="qualified"...
2
by: Maximus | last post by:
Hi Everyone, I was using Inprocess session objects, but incase of aspnet process crashes the session objects were lost as a result I decided to shift to out of porocess session objects. For this...
1
by: Thomas Qvist | last post by:
We are building a suite of programs consisting of both winforms applications and office addins. We would like to pre-generate the xml-serialization classes and add it to our project to avoid...
5
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, We have an app that uses XML serialization throughout. As everyone probably knows, using XML serialization is not always a good idea in a big project...
0
by: JosAH | last post by:
Introduction Upon hearing the word, "Serialization", the first question which comes to mind is ... "What is Serialization?" We know that we can create resusable objects in Java. But the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.