开发者

How to load a XML into a DataSet via XSL with C#

开发者 https://www.devze.com 2023-04-10 08:29 出处:网络
I\'m trying to load a xml which contains metadata, for example: <DataSet> <DataTable id=\"Estrutura\">

I'm trying to load a xml which contains metadata, for example:

<DataSet>
        <DataTable id="Estrutura">
          <Columns>
            <Column FieldName="ORDEM" DisplayLabel="ORDEM" DataType="Integer" Required="0" Size="0"/>
            <Column FieldName="NOME" DisplayLabel="NOME" DataType="String" Required="0" Size="100"/>开发者_JAVA百科;
            <Column FieldName="NIVEL" DisplayLabel="NIVEL" DataType="Integer" Required="0" Size="0"/>
            <Column FieldName="INDICE_IMAGEM" DisplayLabel="INDICE_IMAGEM" DataType="Integer" Required="0" Size="0"/>
            <Column FieldName="TIPO" DisplayLabel="TIPO" DataType="String" Required="0" Size="100"/>
          </Columns>
          <Rows>
            <Row ORDEM="4" NOME="DUnit Pré-Libor6M" NIVEL="3" INDICE_IMAGEM="12" TIPO="Carteira"/>
            <Row ORDEM="3" NOME="DUnit CDI-Libor6M" NIVEL="3" INDICE_IMAGEM="12" TIPO="Carteira"/>
            <Row ORDEM="2" NOME="DUnit RF_Swaps" NIVEL="2" INDICE_IMAGEM="10" TIPO="Pasta"/>
            <Row ORDEM="1" NOME="DUnit RF_Swaps" NIVEL="1" INDICE_IMAGEM="2" TIPO="Tesouraria"/>
            <Row ORDEM="0" NOME="DUnit" NIVEL="0" INDICE_IMAGEM="0" TIPO="Instituição"/>
          </Rows>
        </DataTable>
        <DataTable id="Parametro;RME">
          <Columns>
            <Column FieldName="Definição" DisplayLabel="Definição" DataType="String" Required="0" Size="50"/>
            <Column FieldName="Valor" DisplayLabel="Valor" DataType="String" Required="0" Size="150"/>
          </Columns>
          <Rows>
            <Row Definição="Padrão da Cota" Valor="Fechamento"/>
            <Row Definição="Data Inicial" Valor="11/1/2011"/>
            <Row Definição="Data Final" Valor="12/1/2011"/>
            <Row Definição="Formas Apuração" Valor="Customizado"/>
            <Row Definição="Tipo Preço Stock" Valor="Fechamento"/>
            <Row Definição="Data Atual/Hora" Valor="18/8/2011 17:42:00"/>
            <Row Definição="Usuário" Valor="DUNIT"/>
            <Row Definição="Definições de Cálculo" Valor="Usuário"/>
            <Row Definição="Moeda Visual" Valor="REAL"/>
            <Row Definição="Tipo Financeiro" Valor="Líquida"/>
            <Row Definição="Tipo Rentabilidade" Valor="Líquida"/>
            <Row Definição="Método Rentabilidade" Valor="TIR"/>
            <Row Definição="Quantidade de Barras no Gráfico" Valor="10"/>
            <Row Definição="Usa Todas as Barras no Gráfico" Valor="Não"/>
          </Rows>
        </DataTable>
</DataSet>

Well, how it's possible to see, it's look like a dataset structure, but I'm not getting this do work. I think the way is try xls, but, how can I make a xls which turn this xml code in a xml recognizable by a DataSet. In other words, how can I make this XSL and load it together with XML to be recognizable by the DataSet?

Thank you.


You'll probably want to have a look at how DataSet infers table structure from XML. Looks to me like you'll just need to:

  • delete the column definitions (those are what are inferred),
  • rename your DataTable element to the actual name of the table, and
  • make Row a child element of the new table element.

For example, something like this ought to work:

<DataSet>
 <Estrutura>
   <Row ORDEM="4" NOME="DUnit Pré-Libor6M" NIVEL="3" .../>
   <Row ORDEM="3" NOME="DUnit CDI-Libor6M" NIVEL="3" .../>
   ...

Using an XSL transform to reach this state is a pretty basic use of XSL and shouldn't be too hard with the intros to XSL around the web. I suggest you give it a try and post a new question here on SO when you run into specific XSL problems.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号