Click here to Skip to main content
15,915,160 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I have a dataset with multiple tables (3) and some relations between them. I want to generate a XML that shows this relations. Example of the XML i need to generate:

XML
<?xml version="1.0" encoding="UTF-8"?>
<SalesTransaction xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../sales_transaction.xsd">
  <SalesHeader>
    <HeaderId>5149</HeaderId>
    <CustomerNo>D001</CustomerNo>
    <Location>M01</Location>
    <SalesPerson>123</SalesPerson>
    <Cashier>11</Cashier>
    <SupervisorId>32</SupervisorId>
    <SalesLine>
      <LineId>24240</LineId>
      <HeaderId>5149</HeaderId>
      <ItemNo>0330196</ItemNo>
      <UnitOfMeasure>COPE</UnitOfMeasure>
      <ItemUnitPrice>499.00</ItemUnitPrice>
      <Quantity>1</Quantity>
      <Item>
        <ItemId>405922</ItemId>
        <No>0330196</No>
        <Descr>BOJRA DRURI 12CP HOLLA STAEDLE</Descr>
        <Barcode>4007817144602</Barcode>
        <CategoryCode>ND</CategoryCode>
        <GroupCode>LISX</GroupCode>
        <WarrantyForComponents>true</WarrantyForComponents>
        <Blocked>false</Blocked>
        <ItemBarcode>
          <BarcodeId>1176611</BarcodeId>
          <ItemNo>0330196</ItemNo>
          <Barcode>4007817144602</Barcode>
          <LastDateModified>2012-11-23T23:55:09</LastDateModified>
          <Active>true</Active>
        </ItemBarcode>
      </Item>
    </SalesLine>
  </SalesHeader>
</SalesTransaction>


As you can see the table sales header relates to sales line,and it relates to item etc etc.

How can i generate this,or if its easier to generate it from sqlquery directly??

Thanx in advance.
Posted

Hi, use this below mentioned code for writing xml data from data set.

C#
DataSet ds = new DataSet();
ds.WriteXml(fileName);


or you can use below code to set data in xml format.

C#
DataSet ds = new DataSet();
string data = ds.GetXml();
 
Share this answer
 
v2
Comments
IviKAZAZI 25-Feb-13 5:56am    
yes,its a solution but i culdent set the format xml i wanted.
Finally i endet up using FOR XML statement of sql server 2008,and i got the format i wanted. than the return type from the command i converted as xml doc and thats it!
 
Share this answer
 
Comments
RedDk 25-Feb-13 11:28am    
Show what you did! Stick it between <pre> and </pre>.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900