Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to import data from a xml file into a dataset
this is my xml file
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>04</Fax>
      <Mobile>05</Mobile>
      <House>01</House>
    </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)
How can I import the data like this?

thanks
Posted
Updated 17-Sep-10 14:41pm
v2

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.)
 
Share this answer
 
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?
 
Share this answer
 
v2
Comments
Sandeep Mewara 19-Sep-10 3:55am    
Already suggested you the way.

Further, either use 'Improve Question' link to update your question OR use 'Add comment' feature to respond to an answer. Dont hit answer button when actually it is not an answer.
mhs377 19-Sep-10 13:20pm    
I do not know how to work with XSl files
can you tell me how I can do that?
please give an example for codes
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900