DataRow Prefix

O

occ

Hi,

I have been trying to generate a xml file via typed datasets using the
writexml method. The xml I am after is
<?xml version="1.0" standalone="yes" ?>
- <bw:ABC xmlns:bw="http://tempuri.org/ABC.xsd">
- <bw:Employee>
<bw:EmployeeID>1</EmployeeID>
<bw:EmployeeName>John</EmployeeName>
</bw:Employee>
- <bw:Employee>
<bw:EmployeeID>2</EmployeeID>
<bw:EmployeeName>Peter</EmployeeName>
</bw:Employee>
</bw:ABC>

how ever when I run my code I get the following:

<?xml version="1.0" standalone="yes" ?>
- <bw:ABC xmlns:bw="http://tempuri.org/ABC.xsd">
- <bw:Employee>
<EmployeeID xmlns="http://tempuri.org/ABC.xsd">1</EmployeeID>
<EmployeeName xmlns="http://tempuri.org/ABC.xsd">John</
EmployeeName>
</bw:Employee>
- <bw:Employee>
<EmployeeID xmlns="http://tempuri.org/ABC.xsd">2</EmployeeID>
<EmployeeName xmlns="http://tempuri.org/ABC.xsd">Peter</
EmployeeName>
</bw:Employee>
</bw:ABC>

the csharp code looks like this

ABC bw = new ABC ();
bw.Prefix = "bw";

ABC.EmployeeDataTable employee = (ABC.EmployeeDataTable)bw.Tables
["Employee"];
employee.Prefix = "bw";

ABC.EmployeeRow employeeRow1 = employee.NewEmployeeRow
();

employeeRow1.EmployeeID = 1;
employeeRow1.EmployeeName = "John";
employee.AddEmployeeRow(employeeRow1);

ABC.EmployeeRow employeeRow2 = employee.NewEmployeeRow();
employeeRow2.EmployeeID = 2;
employeeRow2.EmployeeName = "Peter";
employee.AddEmployeeRow(employeeRow2);

bw.WriteXml("c:\\abc.xml");

how can I get rid of the xmlns attribute from the xml file and prefix
with bw.There is no prefix property for DataRow field.
 
J

Jani Järvinen [MVP]

Hi Occ,
I have been trying to generate a xml file via typed datasets using the
writexml method. ... [snip]
how can I get rid of the xmlns attribute from the xml file and prefix
with bw.There is no prefix property for DataRow field.

There's only so much the ready-made WriteXml method can go, but if you have
special requirements on the resultsing XML formatting, I suggest you take
either of these two routes: either output the XML by hand, or create an XSLT
transformation to come up with the required XML.

Outputting the XML by hand can be simple or complex depending on your
dataset structure, but given the XML you showed, I'd expect this to be a
straightforward operation. At least for me, it would take longer to come up
with the XSL transformation file, at least without tools.

On the other hand, if you are interested in the transformations, see here:

http://msdn.microsoft.com/en-us/library/8fd7xytc.aspx

Hope this helps!

--
Regards,

Jani Järvinen
C# MVP
Vantaa, Finland
E-mail: (e-mail address removed)
Business: http://www.nimacon.net/
Personal: http://www.saunalahti.fi/janij/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top