1 Replies - 3851 Views - Last Post: 19 September 2010 - 01:57 PM Rate Topic: -----

#1 MHS333  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-September 07

How to import data from xml file into a dataset

Posted 19 September 2010 - 01:01 PM

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

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Persons>
  <Person Personid="10">
    <firstname>Hi</firstname>
    <lastname>bye</lastname>
    <Birthday>1360 </Birthday>
    <Phones>
      <Fax>04</Fax>
      <Other>05</Other>
      <Home>01</Home>
    </Phones>
    <Emails>
      <Email>Email@site.com</Email>
    </Emails>
    <Webs>
      <Web>web.com</Web>
    </Webs>    
  </Person>  
</Persons>



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)


when the xml file is like below it has these tables:

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 }

<?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?

Is This A Good Question/Topic? 0
  • +

Replies To: How to import data from xml file into a dataset

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: How to import data from xml file into a dataset

Posted 19 September 2010 - 01:57 PM

I suggest you parse the xml yourself... Use LINQ to XML for parsing xml files:

XDocument doc = Xdocument.Load("myxmlfile.xml");
etc...

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1