[Solved] Create xml file with dataset like this format


If you want to create some custom xml that you can use XElement.

How to create <_XPXML Note="" CrtTime="" CN="" DBN="" Srv="" Ver="" AppId="" Class="" IC="" Stock="" Desc="">?

You can use the code below to create.

var node=new XElement("_XPXML ");
node.SetAttributeValue("Note","");
node.SetAttributeValue("CrtTime","");
// ...
// please write the Attribute
doc.Root.Add(node);

Before you use the code that you should new doc as this code

XDocument doc = new XDocument();

And you should add using System.Xml.Linq in file top.

After you set the attribute that you can save it to file.

doc.Save(xx);

The example:

XDocument doc = new XDocument();
XElement node = new XElement("_XPXML");
node.SetAttributeValue("Note", "");
var invTrans = new XElement("_InvTrans");
node.Add(invTrans);
invTrans.SetAttributeValue("IC", "010006");

doc.Add(node);

StringBuilder str = new StringBuilder();
TextWriter stream = new StringWriter(str);
doc.Save(stream);

The str is

<?xml version="1.0" encoding="utf-16"?>
<_XPXML Note="">
  <_InvTrans IC="010006" />
</_XPXML>

5

solved Create xml file with dataset like this format