By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

Assigning objects to object properties of XSD generated classes

P: n/a
I have generated classes based on an Xml schema file (xsd) using the XSD.exe tool.

My goal is to:

- write an application that can parse XML documents
- fill objects (based on the generated classes) with the XML data in element nodes or attributes
- assemble the objects so they are contained in their parent
- add the resulting object to an arrayList

The problem I’m having is that I am not sure how to go about assigning an object to an object variable in the base class. I keep getting conversion errors when I compile indicating "Cannot implicitly convert type Part.[Object variable] to [Object of Same Type as Object Variable]"

The hierarchy of the xml schema is as follows:

<Part nbr=”73894” rev=”9847”>
<Location fac=”Detroit” station=”9782”>
<Step seq=”09”>
<BillOfMaterial><BillOfMaterial>
<Task></Task>
<Illustration></Illustration>
</Step>
</Location>
</Part>

For each element/node in the xml doc,

- I instantiate the corresponding XSD generated object
- assign attribute values to corresponding class property/field
- Next, I attempt to assign child objects to the parent object variables
- LASTLY, I add the object to an arraylist

The syntax/code for one of the generated classes is as follows:

public class PartLocationStep {
public PartLocationStepBillOfMaterials BillOfMaterials;
public PartLocationStepIllustration Illustration;

[System.Xml.Serialization.XmlElementAttribute("Task ")]
public PartLocationStepTask[] Task;

[System.Xml.Serialization.XmlAttributeAttribute
Form=System.Xml.Schema.XmlSchemaForm.Qualified, DataType="integer")]
public string sequence;
}

The syntax I am using is as follows:

partLocStep.BillOfMaterials = partLocStepBOM;
partLocStep.Illustration = partLocStepIllustration;
partLocStep.Task = partLocStepTask;
partLoc.Step = partLocStep;
part.Location = partLoc;

//Add Part Object to Parts collection
partList.Add(part)

Is it my syntax for assigning the individual objects back to the parent object property/variable? Do I need to modify code inside the generated classes? Is there an easier way to do what I am trying to do?

I am fishing for answers? Hopefully, someone out there can help me or point me in the right direction.

Thanks
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.