-1

I'm new for c# and XML. I have xsd file and created cs file from it like described here Generating XML file using XSD file Now I need to generate XML file that contains multiple invoices and every invoice has 1 or more subrows. How to do that?

Community
  • 1
  • 1
Rein Kannumäe
  • 31
  • 1
  • 1
  • 5

1 Answers1

0

1 start VS command prompt

2 generate classes, based on XSD with SvcUtil.exe

svcutil xml_in_arved.xsd /language:C# /dataContractOnly /importxmltypes   /out:class.cs

3 write code to fill classes

XmlDocument doc = new XmlDocument();
doc.LoadXml("<book>" +
                    "  <title>Oberon's Legacy</title>" +
                    "  <price>5.95</price>" +
                    "</book>");

invoices invoices = new invoices();
invoices.Nodes = new XmlNode[2];
invoices.Nodes[0] = doc.CreateNode("element", "test", "myNamespace");
invoices.Nodes[1] = doc.CreateNode("element", "tes2", "myNamespace");

4 serialize classes to xml

Serialize example

var content = invoices;
var filename = @"c:\temp\xmlserialise.xml";
using (TextWriter textWriter = new StreamWriter(filename, false))
{
    var serializer = new XmlSerializer(content.GetType());
    serializer.Serialize(textWriter, content);
}
lordkain
  • 3,061
  • 1
  • 13
  • 18
  • I'm using this xsd http://wiki.directo.ee/_media/et/xml_in_arved.xsd Generated classes. How to fill classes? – Rein Kannumäe Nov 22 '16 at 14:06
  • OK, probably this is right answer, I just don't know how to use it. Like I posted, I'm new to c#. First I generated classes like this xsd.exe /classes xml_in_arved.xsd and it gave me bigger cs file than using svcutil xml_in_arved.xsd /language:C# /dataContractOnly /importxmltypes /out:class.cs Not sure which one is right. – Rein Kannumäe Nov 23 '16 at 06:53
  • look at the difference what is generated and what fits your need. Our job is also some reseach and exploring. – lordkain Nov 23 '16 at 08:16