473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Load XML file into flat table

Hi,

I've been doing a bit of reading on the Internet, but can't work out
what is the best way to load an XML file into a table. The XML file is
normalised, so for each record I create in my database table, I'll need
to grab data from the nodes above.

e.g.

<sex>
<title>Male</title>
<eyecolourgroup>
<colour>blue</colour>
<person>
<name>John</name>
</person>
<person>
<name>Bill</name>
</person>
<colour>brown</colour>
<person>
<name>Fred</name>
</person>
</eyecolourgroup>
</sex>
<sex>
<title>Female</title>
<eyecolourgroup>
<colour>blue</colour>
<person>
<name>Jane</name>
</person>
</eyecolourgroup>
</sex>

I want the data to look like:

Sex colour name
male blue John
male blue Bill
male brown Fred
female blue Jane

Obviously I can traverse the XML and build up the values myself, but I
wondered if there was some sort of magic way I can get the values out.
I've tried loading the data into a Datagrid, but I'm not sure how I can
treat it all as one row.

Any ideas would be much appreciated.

Thanks

Ryan

Jul 26 '06 #1
3 2810
Well, if (as seems to be suggested) there is a way to load xml into a
datagrid when it is in a simple (?xml?) format, then why not run your
existing xml through an xslt stylesheet and use this to re-write the data
into a simpler structure that the datagrid will understand? If the xml is
large, you should do this treating the xml as a stream (e.g. FileStream if
on the hdd), not a DOM (e.g. XmlDocument).

It would be interesting to see how this approach compares (performance wise)
with manually parsing the xml...

Marc
Jul 26 '06 #2
Where is XML located? File on disk, or where?
There are some cases
- use XML bulk load to insert data from xml file to table, smth like
INSERT into MyXMLDocs(MyXMLDoc) SELECT * FROM OPENROWSET
(Bulk 'c:\temp\MyXMLDoc.xml', SINGLE_CLOB) as x
- use XSLT to transfer data into INSERT INTO query

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"ry************@norubbishgmail.com" wrote:
Hi,

I've been doing a bit of reading on the Internet, but can't work out
what is the best way to load an XML file into a table. The XML file is
normalised, so for each record I create in my database table, I'll need
to grab data from the nodes above.

e.g.

<sex>
<title>Male</title>
<eyecolourgroup>
<colour>blue</colour>
<person>
<name>John</name>
</person>
<person>
<name>Bill</name>
</person>
<colour>brown</colour>
<person>
<name>Fred</name>
</person>
</eyecolourgroup>
</sex>
<sex>
<title>Female</title>
<eyecolourgroup>
<colour>blue</colour>
<person>
<name>Jane</name>
</person>
</eyecolourgroup>
</sex>

I want the data to look like:

Sex colour name
male blue John
male blue Bill
male brown Fred
female blue Jane

Obviously I can traverse the XML and build up the values myself, but I
wondered if there was some sort of magic way I can get the values out.
I've tried loading the data into a Datagrid, but I'm not sure how I can
treat it all as one row.

Any ideas would be much appreciated.

Thanks

Ryan

Jul 26 '06 #3
Thanks guys,

Ths file is on disk (about 5-10Mb). Like the idea of the XSLT, never
used it before, but just had a quick play, and managed to get some data
out of my XML file. It looks like there might be a lot to learn
though.

Marc, would love to try both methods, but as I'm fairly new to this, I
think the XSLT might take me enough time on it's own!

Thanks for both your help.

Ryan

Michael Nemtsev wrote:
Where is XML located? File on disk, or where?
There are some cases
- use XML bulk load to insert data from xml file to table, smth like
INSERT into MyXMLDocs(MyXMLDoc) SELECT * FROM OPENROWSET
(Bulk 'c:\temp\MyXMLDoc.xml', SINGLE_CLOB) as x
- use XSLT to transfer data into INSERT INTO query

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


"ry************@norubbishgmail.com" wrote:
Hi,

I've been doing a bit of reading on the Internet, but can't work out
what is the best way to load an XML file into a table. The XML file is
normalised, so for each record I create in my database table, I'll need
to grab data from the nodes above.

e.g.

<sex>
<title>Male</title>
<eyecolourgroup>
<colour>blue</colour>
<person>
<name>John</name>
</person>
<person>
<name>Bill</name>
</person>
<colour>brown</colour>
<person>
<name>Fred</name>
</person>
</eyecolourgroup>
</sex>
<sex>
<title>Female</title>
<eyecolourgroup>
<colour>blue</colour>
<person>
<name>Jane</name>
</person>
</eyecolourgroup>
</sex>

I want the data to look like:

Sex colour name
male blue John
male blue Bill
male brown Fred
female blue Jane

Obviously I can traverse the XML and build up the values myself, but I
wondered if there was some sort of magic way I can get the values out.
I've tried loading the data into a Datagrid, but I'm not sure how I can
treat it all as one row.

Any ideas would be much appreciated.

Thanks

Ryan
Jul 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jane | last post by:
I'm going to use cursor load to load 200GB data in my production database. My database has 2 partitions. but I cannot find more info in the manual about this cursor load. I'm concern about...
1
by: ED | last post by:
Can anyone give me a solution to loading a flat file with an extension of .txt into an access table automatically, aka user clicks a command button. Thanks
1
by: Knepper, Michelle | last post by:
Hi out there, I'm a first-time user of the "Copy ... From..." command, and I'm trying to load a table from a text flat file. http://www.postgresql.org/docs/7.4/static/sql-copy.html I don't...
3
by: vijay_dwi | last post by:
Hi all, I have a fixedwidth .DAT file and a DB2 table, I have to create a flat file by pulling data from both file and DB2 table. I tried using IMPORT/LOAD utilities to load to a global...
7
by: P. Adhia | last post by:
Sorry for quoting an old post and probably I am reading out of context so my concern is unfounded. But I would appreciate if I can get someone or Serge to confirm. Also unlike the question asked in...
9
by: FFMG | last post by:
In my site I have a config table, (MySQL), with about 30 entries; the data is loaded on every single page load. This is not the only call to the db, (we do a total of about 8 calls to the db). As...
1
by: Okonita | last post by:
Hello all, I have a question about loading DB2. I ran a DSN1COPY against a imagecopy of 1 tablespace and the output to a flat file instead of the original DB2 VSAM dataset. Can I use this flat...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.