Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I got a generated class in C# (from a xsd with xsd/c), that got this declaration (together with string-fields, numeric fields and so):

C#
private string[] itemsField;
private ItemsChoiceType[] itemsElementNameField;


The ItemsChoiceType looks like this:
C#
public enum ItemsChoiceType1 {
    colorOfCar,
    colorOfMC,
    colorOfBike,
}


So, If we look at the itemsElementNameField, its an array of enums, but how should I fill it, to make every value as an element in my XML-file?

The method I use to create the xml is:

C#
XmlSerializer XmlSerRoot = new XmlSerializer(typeof(RootInformation)) (the root of my xml!) 
 - StringWriterWithEncoding strWriter = new StringWriterWithEncoding(Encoding.GetEncoding("iso-8859-1"));
 - XmlDocument documentInXML = new XmlDocument();
 - XmlSerRoot.Serialize(strWriter, rootInformation);  
 - string XmlString;
 - XmlString = strWriter.ToString(); 
 - documentInXML.LoadXml(XmlString);
 - documentInXML.Save(myPath);


maybe not of interest, but better to apply some information about it, I thought)

I want this array to be like an ordinary xml-tag in the file, like: <colorOfCar>Blue</colorOfCar>

I got all information I need, like if it's a colorOfCar, and the color of it (like blue). But how should the array look like? I mean, how should I fill it to be ok. It's not working with just something like ItemsChoiceType[1] = "colorOfCar" (I got this info at this stage). But I cannot figure out how the array should be filled to be ok in the end.

Maybe kind of incomplete information, but I think you undertand what I mean.... The main thing is: how to fill an array to be represented as xml-elements in the end.

Regards, /E
Posted
Comments
V. 9-Apr-13 5:36am    
I think you'll need to improve your question, because I have no idea what you want to achieve. You're using a standard serialization function, but you want to customize part of the serialization is that it?
Steve44 9-Apr-13 16:12pm    
From the fragments you provide it looks like you are trying something that looks more complicated than necessary, you are taking two independent arrays and want to map an item from one array to your XML Tag and the matching item from the other array to your XML Element content.
Is there a reason to match exactly this structure or would it be possible to change structure to make it easier to use with the XmlSerializer?
An example of a more straight forward structure would be:
<itemchoice type="colorOfCar">Blue

1 solution

I had no choise but follow a xsd, I only got it in my hand from 3.rd part. That's why it looks a bit confusing. But the solution was easier then I thought. I don't know how this work, but id does. I just filled in the arrays with enums, and it looks nice. The other array keep the values.

Kind of strange that it's ok, but it works.

/E
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900