BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do you save an XML data to a database

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Larry
Guest





PostPosted: Wed Jun 28, 2006 8:11 am    Post subject: How do you save an XML data to a database Reply with quote



I am using a telnet session to read a string. The results are multiple
records in a data packet. I need to parse the XML string and save it to a
MS/SQL database table.

The data is coming from a meat scale and sends its data when I request it.
It will come in the following format.

I created the string below using the CDS Load from table tool. Since I get
to dictate how it is stored, I am able to define the structure. I have
instructed my CE programmer to send the data as below. Ofcourse my real
interest is RowData.

My question is quite simple. When the below string arrives in the buffer as
in :
procedure TForm1.IdTelnet1DataAvailable(Sender: TIdTelnet; const Buffer:
string);

I would like to know a simple way to insert it to an SQL database table.
(SQL 2000)

I suppose I could write my own little parser but that would defeat the
purpose of using an XML encapsulated stream. I want to take advantage of
some simple tools but do not know how.

So, if you were receiving a stream as delineated below, how would you go
about saving it to a SQL table.

I am very adept to SQL and Delphi. Just new to xml.

Using SQL 2000 and D-7 or D-10




<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DATAPACKET Version="2.0">
<METADATA>
<FIELDS>
<FIELD attrname="TXID" fieldtype="i2"/>
<FIELD attrname="GroupID" fieldtype="i2"/>
<FIELD attrname="ScaleID" fieldtype="i2"/>
<FIELD attrname="LineID" fieldtype="i2"/>
<FIELD attrname="StationID" fieldtype="i2"/>
<FIELD attrname="Weight" fieldtype="fixed" DECIMALS="15" WIDTH="18"/>
<FIELD attrname="DateWeighed" fieldtype="dateTime"/>
</FIELDS>
<PARAMS/>
</METADATA>
<ROWDATA>
<ROW TXID="3" GroupID="10" ScaleID="1" LineID="1" StationID="1"
Weight="23.344600000000000" DateWeighed="20060627T16:19:00000"/>
<ROW TXID="3" GroupID="7" ScaleID="1" LineID="1" StationID="7"
Weight="23.581200000000000" DateWeighed="20060627T16:24:00000"/>
<ROW TXID="3" GroupID="7" ScaleID="1" LineID="1" StationID="7"
Weight="24.581200000000000" DateWeighed="20060627T16:25:18150"/>
<ROW TXID="4" GroupID="7" ScaleID="1" LineID="1" StationID="7"
Weight="24.580200000000000" DateWeighed="20060627T16:25:30350"/>
</ROWDATA>
</DATAPACKET>



SAVE THE ABOVE INTO THE TABLE BELOW

CREATE TABLE [dbo].[DualIndexer] (
[TXID] [tinyint] NULL ,
[GroupID] [tinyint] NULL ,
[ScaleID] [tinyint] NULL ,
[LineID] [tinyint] NULL ,
[StationID] [tinyint] NULL ,
[Weight] [decimal](18, 15) NULL ,
[DateWeighed] [datetime] NULL
) ON [PRIMARY]
GO
Back to top
Steve Zimmelman
Guest





PostPosted: Fri Jul 07, 2006 6:33 pm    Post subject: Re: How do you save an XML data to a database Reply with quote



Hi Larry,

I'm not that familiar with xml either, but if the xml is compatible with
TADODataSet, you can use the LoadFromFile method and can spin through the
recordset and insert the data into the SQL table. You can also load it from a
stream into the AdoDataSet, but that isn't a native method. Let me know if you
want to go that route and I'll send you the methods I use for saving and loading
data from streams for AdoDataSets.

-Steve-

"Larry" <lkillen (AT) charter (DOT) net> wrote in message
news:44a1f88e (AT) newsgroups (DOT) borland.com...
Quote:
I am using a telnet session to read a string. The results are multiple records
in a data packet. I need to parse the XML string and save it to a MS/SQL
database table.

The data is coming from a meat scale and sends its data when I request it. It
will come in the following format.

I created the string below using the CDS Load from table tool. Since I get to
dictate how it is stored, I am able to define the structure. I have
instructed my CE programmer to send the data as below. Ofcourse my real
interest is RowData.

My question is quite simple. When the below string arrives in the buffer as
in :
procedure TForm1.IdTelnet1DataAvailable(Sender: TIdTelnet; const Buffer:
string);

I would like to know a simple way to insert it to an SQL database table. (SQL
2000)

I suppose I could write my own little parser but that would defeat the purpose
of using an XML encapsulated stream. I want to take advantage of some simple
tools but do not know how.

So, if you were receiving a stream as delineated below, how would you go about
saving it to a SQL table.

I am very adept to SQL and Delphi. Just new to xml.

Using SQL 2000 and D-7 or D-10




?xml version="1.0" encoding="UTF-8" standalone="yes"?
DATAPACKET Version="2.0"
METADATA
FIELDS
FIELD attrname="TXID" fieldtype="i2"/
FIELD attrname="GroupID" fieldtype="i2"/
FIELD attrname="ScaleID" fieldtype="i2"/
FIELD attrname="LineID" fieldtype="i2"/
FIELD attrname="StationID" fieldtype="i2"/
FIELD attrname="Weight" fieldtype="fixed" DECIMALS="15" WIDTH="18"/
FIELD attrname="DateWeighed" fieldtype="dateTime"/
/FIELDS
PARAMS/
/METADATA
ROWDATA
ROW TXID="3" GroupID="10" ScaleID="1" LineID="1" StationID="1"
Weight="23.344600000000000" DateWeighed="20060627T16:19:00000"/
ROW TXID="3" GroupID="7" ScaleID="1" LineID="1" StationID="7"
Weight="23.581200000000000" DateWeighed="20060627T16:24:00000"/
ROW TXID="3" GroupID="7" ScaleID="1" LineID="1" StationID="7"
Weight="24.581200000000000" DateWeighed="20060627T16:25:18150"/
ROW TXID="4" GroupID="7" ScaleID="1" LineID="1" StationID="7"
Weight="24.580200000000000" DateWeighed="20060627T16:25:30350"/
/ROWDATA
/DATAPACKET



SAVE THE ABOVE INTO THE TABLE BELOW

CREATE TABLE [dbo].[DualIndexer] (
[TXID] [tinyint] NULL ,
[GroupID] [tinyint] NULL ,
[ScaleID] [tinyint] NULL ,
[LineID] [tinyint] NULL ,
[StationID] [tinyint] NULL ,
[Weight] [decimal](18, 15) NULL ,
[DateWeighed] [datetime] NULL
) ON [PRIMARY]
GO


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.