Link to home
Start Free TrialLog in
Avatar of XGIS
XGISFlag for Australia

asked on

Export XML using C# as Attribute Rows

I need my exports to look like this;
<?xml version="1.0" encoding="utf-8" ?>
<Items>
    <Item Name="Afghanistan" ID="296" />
<Items>

Open in new window

and NOT this (as they are now)
<?xml version="1.0" standalone="yes"?>
<Items>
  <Item>
    <ID>296</ID>
    <Name>Afghanistan</Name>
  </Item>

Open in new window

My export Code is this;
            
var adapter4 =
new SqlDataAdapter("SELECT [Name],[ID],[PID1] FROM dbo.Countries where PID1 = 14  ORDER BY Name ASC", connection);
var dt4 = new DataTable("Item");
adapter4.Fill(dt4);
DataSet ds4 = new DataSet("Items");
ds4.Tables.Add(dt4);
ds4.WriteXml("C:\\inetpub\\wwwroot\\XR8\\App_Data\\XML\\Countries.xml", System.Data.XmlWriteMode.IgnoreSchema);

Open in new window

What am I missing? Please advise?
ASKER CERTIFIED SOLUTION
Avatar of jayakrishnabh
jayakrishnabh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of XGIS

ASKER

Hello jayakrishnabh...
I did try a for each but obviously not the right way. Excellent Job.. it data-binded immediately.
Thankyou
Aaron