473,394 Members | 1,755 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,394 software developers and data experts.

Converting xml data to csv data

Is it posibble to develop codes to convert and xml data to csv data ?
If it is...can i know if there are any online toturials that i can follow to learn on this ?
Aug 14 '07 #1
8 4044
While I'm pretty sure there are some IDEs out there that can do that, I would recommend an XSLT to do so.
Aug 14 '07 #2
jkmyoung
2,057 Expert 2GB
If you have an xml in the following form:
<table>
<row>
<data>value</data>
<data>value</data>
</row>
</table>

You can easily create either scripts or xslt to convert the document. eg. xslt:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="row">
  2.   <xsl:for-each select="data">
  3.     <xsl:value-of select="."/>
  4.     <xsl:if test="not(last())">,</xsl:if>
  5.   </xsl:for-each>
  6.   <xsl:text>
  7. </xsl:text><!-- new line -->
  8. </xsl:template>
However, if you have a very large document and performance is an issue, I would try an alternative to XSLT since XSLT requires a decent amount of overhead to build a DOM.

As it is, we'd have to know what languages you can work with, and the form of your input to know more.
Aug 14 '07 #3
Hi,
i want to convert xml data to csv data so that i can export it into MySQL database....using php or javascript...the aren't much working examples online....can anyone suggest any tutorial online site for me to visit...?
Thanks
Aug 15 '07 #4
jkmyoung
2,057 Expert 2GB
You need to break this down into 2 seperate tasks:

1. Convert xml to csv.
2. Load csv into MySQL

For #2, you're probably going to be using PHP as opposed to javascript.
One way is here:
http://dev.mysql.com/doc/refman/5.0/en/load-data.html
Expand|Select|Wrap|Line Numbers
  1. LOAD DATA LOCAL INFILE '/importfile.csv'
  2.     INTO TABLE test_table
  3.     FIELDS TERMINATED BY ','
  4.     LINES TERMINATED BY '\n'
  5.     (field1, field2, field3);
For #1, again taking advantage of existing XSLT processors would probably be the easiest for you, using the XSLT given above.
http://ca3.php.net/manual/en/functio...orm-to-xml.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Load the XML source
  4. $xml = new DOMDocument;
  5. $xml->load('collection.xml');
  6.  
  7. $xsl = new DOMDocument;
  8. $xsl->load('collection.xsl');
  9.  
  10. // Configure the transformer
  11. $proc = new XSLTProcessor;
  12. $proc->importStyleSheet($xsl); // attach the xsl rules
  13.  
  14. echo $proc->transformToXML($xml);
  15.  
  16. ?> 
Aug 15 '07 #5
Hi,
Just out of curiousity....can we export xml data to mySQL database directy?
Without converting it to csv?
Thanks for helping...!!!
Aug 16 '07 #6
asearle
39
Hi guys,

I've been following this thread as I also need to export to CSV (so that the user can import to Excel) but unfortunately I cannot use any server-side actions (e.g. PHP).

I am using XSLT along with JavaScript and so am hoping that someone can point me towards a HOWTO that shows me how I could (easily) export data (often already dynamically filtered in with JavaScript/XSLT) to file.

Any tips here would be most welcome.

Regards,
Alan Searle
Aug 21 '07 #7
jkmyoung
2,057 Expert 2GB
Old way of doing it with javascript:
http://www.w3schools.com/xsl/xsl_client.asp
but instead of using document.write, save the result to a file.

Another way:
http://developer.mozilla.org/en/docs...ransformations

Converting xml to csv with xslt:
http://www.thescripts.com/forum/thread696548.html

I'm unaware of how to bulk load xml with mySQL; there are definitely methods with MSSQL, using mapping schemas.
Aug 21 '07 #8
asearle
39
These tips look great. Many thanks: I will experiment with these techniques and am sure that one will fit my needs.

There is one other thing that I will need to sort out which is how to save the result to a separate (text) file or maybe open directly in Notepad.

Here I have been googling on key words but tend to come up with a lot of commercial products offering this functionality. That's very nice but really I would like to understand the whole process and be able to do it myself so was wondering whether you have any pointers to a HOWTO showing how this can be done (maybe with javascript)?

Many thanks,
Alan Searle
Aug 28 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Dan Stromberg | last post by:
I've written up a page about how to convert native binary data to another platform's native binary data, as I did some fortran data conversions for a client. The programs and documentation are...
2
by: Govind | last post by:
Hi All, I want to Convert 32 bit integers to byte in right alighed format . For 32 = the usual way is BitConverter.GetBytes(int32)==> xx xx 00 00 , but i want right aligned like 00 00 xx xx.Is...
4
by: mustafa | last post by:
Dear sir , I have built my application in visual basic 6.0 and crystal Report8.5 , Now i migrated my application to VB.net using the upgrade wizard.My visual basic form is upgraded to vb.net...
3
by: Pete Davis | last post by:
I've never done this in C# so I don't know what the appropriate way of doing it is. I've got an array of bytes and I need to convert the array into "usable" data. For example, the first 4 bytes...
32
by: robert d via AccessMonster.com | last post by:
I'm looking at converting DAO to ADO in my app. All of my DAO connections are of the following structure: Dim wsName As DAO.Workspace Dim dbName As DAO.Database Dim rsName As DAO.Recordset ...
3
by: Sharon | last post by:
I have a buffer of byte that contains a raw data of a 1 byte-per-pixel image data. I need to convert this buffer to a Bitmap of Format32bppArgb and to a Bitmap of Format24bppRgb. Can anybody...
4
by: Bob Alston | last post by:
Anyone have experience with converting an access app from Jet database to Mysql? I am specifically looking for any changes I would have to make to my access forms, queries, modules, vba code, etc....
1
by: SLC via DBMonster.com | last post by:
Hello I'm a newbie to this and I need help, please My question is, we currently have a IDMS db and will be converting to DB2. What are the things I should do? The IDMS has not been documented very...
3
by: psbasha | last post by:
Hi , When ever we read any data from file ,we read as a single line string ,and we convert the respective field data available in that string based on the data type ( say int,float ). ...
0
Krishna Ladwa
by: Krishna Ladwa | last post by:
In Sql Server 2000 Version, I found that no Notification message box appears when converting text column to varchar but the data gets truncated to the given size for the varchar. Whereas it appears...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.