У меня есть файл XSD. Я получаю данные от SQL и заполняю данные в наборе данных. примечание: я получаю 1000 записей из SQL.Создание XML из существующего XSD-файла (комплекса)
Я хочу это сделать; генерировать XML-файл, выходящий из формата xsd.
Вот мой XSD .:
<xs:element name = 'automation'>
<xs:complexType>
<xs:sequence>
<xs:element name = 'auto' type = 'AutoType' minOccurs = '1' maxOccurs = 'unbounded' />
</xs:sequence>
</xs:complexType>
<xs:complexType name = "AutoType">
<xs:sequence>
<xs:element name = "autoKodu" type = "xs:string" minOccurs = '1' maxOccurs = '1' /> <!-- v -->
<xs:element name = "autoAdres" type = "xs:string" minOccurs = '1' maxOccurs = '1' /> <!-- v -->
<xs:element name = 'bill' type = 'BillType' minOccurs = '1' maxOccurs = 'unbounded' />
</xs:sequence>
<xs:complexType name = "BillType">
<xs:sequence>
<xs:element name = "dateOne" type = "xs:date" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "dateTwo" type = "xs:time" minOccurs = '1' maxOccurs = '1' />
<xs:element name = 'point' type = 'PointType' minOccurs = '1' maxOccurs = 'unbounded' />
</xs:sequence>
<xs:complexType name = "PointType">
<xs:sequence>
<xs:element name = "plate" minOccurs = '1' maxOccurs = '1' > <!-- v -->
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([a-zA-Z0-9])*"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name = "aa" type = "xs:string" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "bb" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "cc" type = "xs:string" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "dd" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "ee" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "ff" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "gg" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' />
<xs:element name = "hh" type = "xs:decimal" minOccurs = '1' maxOccurs = '1' />
</xs:sequence>
Я создал класс xsd, используя xsd.exe Я добавил его в решение.
var data = new myClassOrSmthng? { ??? I do not know how to get datas from dataset here. }
XmlSerializer serializer = new XmlSerializer(typeof(myClassOrSmthng));
using (var stream = new StreamWriter(myPath)) serializer.Serialize(stream, data);
Спасибо за быстрый ответ. Я уже делал Automation.cs. для чего я должен писать strXML? – jancooth
Пример предполагает, что ваш контент находится в строке с именем strXML. – Zesty