处理C#生成xml的数组? [英] Handle arrays in C# generating xml?
问题描述
您好。我在C#中生成了一个生成的类(来自xsd和xsd / c),得到了这个声明(连同字符串字段,数字字段等):
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):
private string[] itemsField;
private ItemsChoiceType[] itemsElementNameField;
ItemsChoiceType的外观像这样:
The ItemsChoiceType looks like this:
public enum ItemsChoiceType1 {
colorOfCar,
colorOfMC,
colorOfBike,
}
所以,如果我们查看itemsElementNameField,它是一个枚举数组,但我应该如何填充它,将每个值作为我的XML文件中的元素?
方法我用来创建xml是:
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:
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);
可能不感兴趣,但最好应用一些有关它的信息,我我希望这个数组就像文件中的普通xml标签,如:< colorOfCar> Blue< / colorOfCar>
我得到了我需要的所有信息,比如它是colorOfCar,还有它的颜色(比如蓝色)。但阵列怎么样?我的意思是,我应该如何填写它才行。它不能像ItemsChoiceType [1] =colorOfCar那样工作(我在这个阶段得到了这个信息)。但我无法弄清楚最后应该如何填充阵列。
也许是一些不完整的信息,但我认为你的意思是我的意思.. ..主要是:如何填充一个数组,最后表示为xml元素。
问候,/ E
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
推荐答案
我没有选择但是遵循xsd,我只从第3部分手中拿到了它。这就是为什么它看起来有点令人困惑。但是我认为解决方案更容易。我不知道这是怎么回事,但我知道。我只是用枚举填充数组,看起来不错。另一个数组保留了这些值。
有点奇怪,没关系,但它确实有效。
/ E
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
这篇关于处理C#生成xml的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!