Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 I don't recieve any datas from xml

Author  Topic 

sql_the_beginner
Starting Member

2 Posts

Posted - 2007-01-16 : 10:44:00
Hello everybody.
I'm really the beginner in programming and I have a problem woth importing xml into sql 2000 server.
I have this xml document:
<?xml version="1.0"?>
<DtecBS xmlns="http://www.bsi.si" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bsi.si http://www.bsi.si/_data/tecajnice/DTecBS.xsd">
<tecajnica datum="2007-01-12">
<tecaj oznaka="USD" sifra="840">1.2893</tecaj>
<tecaj oznaka="DKK" sifra="208">7.4529</tecaj>
</tecajnica>
</DtecBS>

When I use:
SELECT *
FROM OPENXML (@idoc, 'DtecBS/tecajnica/tecaj', 2)
WITH (oznaka varchar (3) '@oznaka',
sifra varchar(10) '@sifra',
tecaj decimal(18,4) 'text()')

all I get is blank columns with names 'oznaka','sifra' and 'tecaj'.
Any ideas why?
Thanks for any help.

Dado

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-16 : 13:18:12
Unfortunately OPENXML and sp_xml_preparedocument don't automatically use the default namespace, so you have to declare it and use it explicity, like this:

DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc ='<?xml version="1.0"?>
<DtecBS xmlns="http://www.bsi.si" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bsi.si http://www.bsi.si/_data/tecajnice/DTecBS.xsd">
<tecajnica datum="2007-01-12">
<tecaj oznaka="USD" sifra="840">1.2893</tecaj>
<tecaj oznaka="DKK" sifra="208">7.4529</tecaj>
</tecajnica>
</DtecBS>'
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc, '<root xmlns:bsi="http://www.bsi.si"/>'

SELECT *
FROM OPENXML (@idoc, 'bsi:DtecBS/bsi:tecajnica/bsi:tecaj', 2)
WITH (oznaka varchar (3) '@oznaka',
sifra varchar(10) '@sifra',
tecaj decimal(18,4) 'text()')

-- Remove the internal representation.
exec sp_xml_removedocument @idoc
Go to Top of Page

sql_the_beginner
Starting Member

2 Posts

Posted - 2007-01-17 : 02:25:23
Thanx a lot!
I've tried a lot of of options, but not this one.

Thanks again.

Dado
Go to Top of Page
   

- Advertisement -