由WriteXML方法创建的XML文件中的自定义XML格式 [英] Custom XML format in XML file created by WriteXML method

查看:84
本文介绍了由WriteXML方法创建的XML文件中的自定义XML格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello all $
我遇到了类似的问题。

在我的ASP.NET 3.5网页中,我需要转换一个Datatable

在XML文件中并将其保存在用户的C:\ root上。



我的数据表有这样的输出(来自我在数据库中的SELECT子句):

Hello all
I have a similar problem.
In my ASP.NET 3.5 webpage I need to convert a Datatable
in a XML file and save it on the C:\ root of the users.

My datatable has an output like this (from my SELECT clause in the database):

标题1    标题2         up_bde    价值

RIC_MGP     STIME-MGP     UP_1     70.68

RIC_MGP     STIME-MGP     UP_2     3.82

RIC_MGP     STIME-MGP     UP_3     0.5

RIC_MI     STIME-MI     UP_1     0.9

RIC_MI     STIME-MI     UP_2     69.2

RIC_MI     STIME-MI     UP_3     47.03

....

Title1    Title2        up_bde    Value
RIC_MGP    STIME-MGP    UP_1    70.68
RIC_MGP    STIME-MGP    UP_2    3.82
RIC_MGP    STIME-MGP    UP_3    0.5
RIC_MI    STIME-MI    UP_1    0.9
RIC_MI    STIME-MI    UP_2    69.2
RIC_MI    STIME-MI    UP_3    47.03
....

此刻我' m使用Dataset类的WriteXML方法,例如:

At this moment I'm using the WriteXML method of the Dataset class, like:

// Writing XML file
var dsExportSAP = new DataSet();
dsExportSAP.Tables.Add(result);
dsExportSAP.WriteXml("C:\\Temp\\testExport.xml");  

这很好用,但我需要输出文件的特定格式。

这是所需的格式(对于我的数据表的第一条记录)。

This works fine, but I need a particular format for the output file.
This is the desidered format (for the first record of my datatable).

<CVRList>
<Title1 Title="RIC-MGP">
<Title2 Title="STIME-MGP">
	<UP Name="UP_1">70.68</UP>
</Title2>
</Title1>
....

相反,我得到了这个XML文件:

Instead I got this XML file:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Table1>
    <Title1>RIC_MGP</Title1>
    <Title2>STIME-MGP</Title2>
    <up_bde>UP_1</up_bde>
    <Value>2689370.68326</Value>
  </Table1>
  ...



如何强制使用这种特定的XML格式?



非常感谢提前。



$
Luigi


How can I force this particular XML format?

Thanks a lot in advance.


Luigi

推荐答案

Hi Luigi,

Hi Luigi,

它是可以通过设置
DataColumn.ColumnMapping <将列映射为属性/ a>属性到MappingType.Attribute。如果我们现在调用DataSet.WriteXml()方法,则列将被写为属性。

It is possible to map the columns as attributes by setting DataColumn.ColumnMapping property to MappingType.Attribute. If we call DataSet.WriteXml() method now, the columns will be written as attributes.

但是,我担心我们无法通过调用WriteXml方法来自定义生成xml。您可能需要编写一个方法来自行序列化为xml。

However, I'm afraid we cannot customize the generate xml so much by calling WriteXml method. You may need to write a method to serialize to xml yourself.

最好的问候,


这篇关于由WriteXML方法创建的XML文件中的自定义XML格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆