如何将数据从xml文件导入数据集中 [英] How to import data from xml file into a dataset

查看:92
本文介绍了如何将数据从xml文件导入数据集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据从xml文件导入到数据集中
这是我的xml文件

I want to import data from a xml file into a dataset
this is my xml file

<br />
<pre lang="xml"><?xml version="1.0" encoding="UTF-8" standalone="no"?><br />
<Persons><br />
  <Person Personid="10"><br />
    <firstname>hi</firstname><br />
    <lastname>bye</lastname><br />
    <Birthday>1980 </Birthday><br />
    <Phones><br />
      <Fax>04</Fax><br />
      <Mobile>05</Mobile><br />
      <House>01</House><br />
    </Phones><br />
    <Emails><br />
      <Email>Email@site.com</Email><br />
    </Emails><br />
    <Webs><br />
      <Web>web.com</Web><br />
    </Webs><br />
  </Person><br />
</Persons></pre><br />


当我使用此代码时
dataset1.readxml(FilePath);

我的数据集中有这些表
人,电话,电子邮件,网站
但我想为传真,手机,房屋,电子邮件,Web提供五个(更多)表
已连接到人"表(传真,移动电话,房屋已连接到电话,电子邮件到电子邮件和Web到网站)
我该如何导入数据?

感谢


when I use this code
dataset1.readxml(FilePath);

I have these tables in my dataset
Person,Phones,Emails,Webs
But I want to have FIVE (more) tables for Fax,Mobile,House,Email,Web
that ARE connected to "Person" table (Fax,Mobile,House are connected to Phones , Email to Emails AND Web to Webs)
How can I import the data like this?

thanks

推荐答案

您还没有提到如何获取此XML,以及是否可以在源代码处更改结构.因此,这是一个选项:
1.创建一个 XSL 文件,并在该源XML上执行XSLT,以获取新XML,其中所有所需数据都处于同一级别.
2.使用此新XML导入数据集.

当前,问题在于存储数据的层次结构.如果您需要将所有数据都存储为表格存储在数据集中,则需要将所有所需数据都置于同一级别. (当前,传真,移动等在XML树的深层中.)
You have not mentioned anything on how you got this XML and if the structure can be changed at source or not. So, here is an option:
1. Creat a XSL file and perform a XSLT on this source XML to get a new XML where all the desired data is at same level.
2. Use this new XML for importing into dataset.

Currently, the issue is the hierarchy in which data is stored. If you need all of them to be stored as a table in dataset then you need to have all the desired data at same level. (Currently, Fax, Mobile, etc are one level deep in the XML tree.)


我使用此代码创建xml文件
dataset1.writexml(FilePath);
xml文件可以更改
当xml文件如下所示时,它具有这些表:
人,电话,电子邮件,网站,传真,手机,房屋,电子邮件,网站

{电子邮件连接到电子邮件},{网络连接到网络}和{电话连接到传真,房屋和移动电话}

I use this code to create the xml file
dataset1.writexml(FilePath);
the xml file can be changed
when the xml file is like below it has these table:
Person,Phones,Emails,Webs,Fax,Mobile,House,Email,Web

{ Emails connects to Email},{ Webs connects to Web } AND { Phones connects to fax,house and mobile }

<pre lang="xml">"xml"><?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Persons>
  <Person Personid="10">
    <firstname>hi</firstname>
    <lastname>bye</lastname>
    <Birthday>1980 </Birthday>
    <Phones>
      <Fax>044</Fax>
      <Mobile>055</Mobile>
      <House>011</House>
      <Fax>04</Fax>
      <Mobile>05</Mobile>
      <House>01</House>
    </Phones>
    <Emails>
      <Email>Email1@site.com</Email>
      <Email>Email2@site.com</Email>
    </Emails>
    <Webs>
      <Web>web1.com</Web>
      <Web>web2.com</Web>
    </Webs>
  </Person>
</Persons>



我想一直有这些表
有什么办法吗?



I want to always have these tables
is there any way?


这篇关于如何将数据从xml文件导入数据集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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