iNET Interactive - Online Advertising Agency

          
 


Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you would prefer not to see any double-underlined words and corresponding advertisements, please click here.

Go Back  dBforums > Usenet Groups > microsoft.public.sqlserver.* > microsoft.public.sqlserver.xml > XML bulkload help

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-19-02, 01:30
Rona Yang
 
Posts: n/a
XML bulkload help

Hi experts,

I am trying to bulk load an xml doc that looks like this:

<topelement> <word text="ball"> <match matchID="1" /> <match matchID="1234" /> <match
matchID="56" /> ... </word> <word text="puck"> <match matchID="5643" /> ... </word>
... </topelement>

into a single table that has two columns: word_text and match_id. It's a one-to-many
relationship of a word to many matches. How can I implement this using SQLXML mapping
schemas (XSD)?

Thanks.

*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in
USENET...get rewarded for it!
Reply With Quote
  #2  
Old 03-19-02, 10:56
Clint
 
Posts: n/a
XML bulkload help

Hello, Are you trying to get an idea on how to write your schema for this
database layout?

Here is a rough draft that will get you started:

<?xml version="1.0" ?> <Schema xmlns="urn.schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:xml-sql" >

<ElementType name="topelement" sql:is-constant="1"> <element type="word" />
</ElementType>

<ElementType name="word" sql:relation="Words"> <AttributeType name="text" />
<attribute type="text" sql:field="word_text" />

<element type="match"> <sql:relationship key-relation="word" key="matchID"
foreign-key="matchID" foreign-relation="matches" /> </element> </ElementType>

Ive some assumptions about your database schema, but this should be a good
starting point.

Best of luck:
C. Field MCDBA

  >TEST--Original MessageTEST-- Hi experts,
  >
  >I am trying to bulk load an xml doc that looks like this:
  >
  ><topelement> <word text="ball"> <match matchID="1" /> <match matchID="1234" />
  ><match matchID="56" /> ... </word> <word text="puck"> <match matchID="5643" /> ...
  ></word> ... </topelement>
  >
  >into a single table that has two columns: word_text and
match_id. It's
  >a one-to-many relationship of a word to many matches.
How can I
  >implement this using SQLXML mapping schemas (XSD)?
  >
  >Thanks.
  >
  >*** Sent via Developersdex http://www.developersdex.com
***
  >Don't just participate in USENET...get rewarded for it! .
Reply With Quote
  #3  
Old 03-19-02, 13:58
Mike Weeder
 
Posts: n/a
XML bulkload help

Clint,

Looks to me that you gave an xdr mapping instead of an xsd. Does XML Bulk Load
support xsd?

/\/\ike

  >TEST--Original MessageTEST-- Hello, Are you trying to get an idea on how to write
  >your schema for this database layout?
  >
  >Here is a rough draft that will get you started:
  >
  ><?xml version="1.0" ?> <Schema xmlns="urn.schemas-microsoft-com:xml-data"
  >xmlns:dt="urn:schemas-microsoft-com:datatypes"
  >xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
  >
  ><ElementType name="topelement" sql:is-constant="1"> <element type="word" />
  ></ElementType>
  >
  ><ElementType name="word" sql:relation="Words"> <AttributeType name="text" />
  ><attribute type="text" sql:field="word_text" />
  >
  > <element type="match"> <sql:relationship key-relation="word" key="matchID"
  > foreign-key="matchID" foreign-relation="matches" /> </element> </ElementType>
  >
  >
  >Ive some assumptions about your database schema, but this should be a good
  >starting point.
  >
  >Best of luck:
  >C. Field MCDBA
  >
  >
     >>TEST--Original MessageTEST-- Hi experts,
     >>
     >>I am trying to bulk load an xml doc that looks like this:
     >>
     >><topelement> <word text="ball"> <match matchID="1" /> <match matchID="1234" />
     >><match matchID="56" /> ... </word> <word text="puck"> <match matchID="5643" /> ...
     >></word> ... </topelement>
     >>
     >>into a single table that has two columns: word_text and
  >match_id. It's
     >>a one-to-many relationship of a word to many matches.
  >How can I
     >>implement this using SQLXML mapping schemas (XSD)?
     >>
     >>Thanks.
     >>
     >>*** Sent via Developersdex http://www.developersdex.com
  >***
     >>Don't just participate in USENET...get rewarded for it! .
     >>
  >.
Reply With Quote
  #4  
Old 03-19-02, 13:58
Clint
 
Posts: n/a
XML bulkload help

Yep. I recently used a similar xdr to do a similar import. It works very well.

I think this link may give some good info.
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/xmlsql/ac_mschema_78q1.asp

Also, check out Graeme Malcolm's book
(http://www.microsoft.com/mspress/boo...178.asp#TableO fContents). Good examples
of doing this.

Cheers!

  >TEST--Original MessageTEST-- Clint,
  >
  >Looks to me that you gave an xdr mapping instead of an xsd. Does XML Bulk Load
  >support xsd?
  >
  >/\/\ike
  >
     >>TEST--Original MessageTEST-- Hello, Are you trying to get an idea on how to
     >>write your
schema
     >>for this database layout?
     >>
     >>Here is a rough draft that will get you started:
     >>
     >><?xml version="1.0" ?> <Schema xmlns="urn.schemas-microsoft-com:xml-data"
     >>xmlns:dt="urn:schemas-microsoft-com:datatypes"
     >>xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
     >>
     >><ElementType name="topelement" sql:is-constant="1"> <element type="word" />
     >></ElementType>
     >>
     >><ElementType name="word" sql:relation="Words"> <AttributeType name="text" />
     >><attribute type="text" sql:field="word_text" />
     >>
     >> <element type="match"> <sql:relationship key-relation="word" key="matchID"
     >> foreign-key="matchID" foreign-relation="matches" /> </element> </ElementType>
     >>
     >>
     >>Ive some assumptions about your database schema, but
this
     >>should be a good starting point.
     >>
     >>Best of luck:
     >>C. Field MCDBA
     >>
     >>
       >>>TEST--Original MessageTEST-- Hi experts,
       >>>
       >>>I am trying to bulk load an xml doc that looks like
this:
       >>>
       >>><topelement> <word text="ball"> <match matchID="1" /> <match matchID="1234" />
       >>><match matchID="56" /> ... </word> <word text="puck"> <match matchID="5643" /> ...
       >>></word> ... </topelement>
       >>>
       >>>into a single table that has two columns: word_text and
     >>match_id. It's
       >>>a one-to-many relationship of a word to many matches.
     >>How can I
       >>>implement this using SQLXML mapping schemas (XSD)?
       >>>
       >>>Thanks.
       >>>
       >>>*** Sent via Developersdex http://www.developersdex.com
     >>***
       >>>Don't just participate in USENET...get rewarded for it! .
       >>>
     >>.
     >>
  >.
Reply With Quote
  #5  
Old 03-19-02, 13:58
Mike Weeder
 
Posts: n/a
XML bulkload help

Clint,

Thanks for the info. But again, I need to know does sqlxml suport ~XSD~ mappings. XSD
is the w3c standard, not the microsoft standard. I am using XML Spy to help me write
these mappings and the export from my SQLdatabase comes in as an XSD schema. When I
convert it to XDR, I lose the sql namesspace support. I really like XML spy for what
it is doing (and already paid my $500).

If not, do you know of any tool that does an export of an existing database to an XDR
schema definition.

Here is the bottom line. I am using BizTalk to import xml documents. I plan to use
the Mapper to map from my input xml document to the sqlxml schema map. Then do the
XML Bulk upload from there. Is there a better way to do this?

Thanks again for your time.

/\/\ike
  >TEST--Original MessageTEST-- Yep. I recently used a similar xdr to do a similar
  >import. It works very well.
  >
  >I think this link may give some good info.
  >http://msdn.microsoft.com/library/default.asp?
  >url=/library/en-us/xmlsql/ac_mschema_78q1.asp
  >
  >Also, check out Graeme Malcolm's book
  >
(http://www.microsoft.com/mspress/boo...178.asp#TableO
  >fContents). Good examples of doing this.
  >
  >Cheers!
  >
     >>TEST--Original MessageTEST-- Clint,
     >>
     >>Looks to me that you gave an xdr mapping instead of an xsd. Does XML Bulk Load
     >>support xsd?
     >>
     >>/\/\ike
     >>
       >>>TEST--Original MessageTEST-- Hello, Are you trying to get an idea on how to
       >>>write your
  >schema
       >>>for this database layout?
       >>>
       >>>Here is a rough draft that will get you started:
       >>>
       >>><?xml version="1.0" ?> <Schema xmlns="urn.schemas-microsoft-com:xml-data"
       >>>xmlns:dt="urn:schemas-microsoft-com:datatypes"
       >>>xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
       >>>
       >>><ElementType name="topelement" sql:is-constant="1"> <element type="word" />
       >>></ElementType>
       >>>
       >>><ElementType name="word" sql:relation="Words"> <AttributeType name="text" />
       >>><attribute type="text" sql:field="word_text" />
       >>>
       >>> <element type="match"> <sql:relationship key-relation="word" key="matchID"
       >>> foreign-key="matchID" foreign-relation="matches" /> </element> </ElementType>
       >>>
       >>>
       >>>Ive some assumptions about your database schema, but
  >this
       >>>should be a good starting point.
       >>>
       >>>Best of luck:
       >>>C. Field MCDBA
       >>>
       >>>
       >>>>TEST--Original MessageTEST-- Hi experts,
       >>>>
       >>>>I am trying to bulk load an xml doc that looks like
  >this:
       >>>>
       >>>><topelement> <word text="ball"> <match matchID="1" /> <match matchID="1234" />
       >>>><match matchID="56" /> ... </word> <word text="puck"> <match matchID="5643" />
       >>>>... </word> ... </topelement>
       >>>>
       >>>>into a single table that has two columns: word_text
and
       >>>match_id. It's
       >>>>a one-to-many relationship of a word to many matches.
       >>>How can I
       >>>>implement this using SQLXML mapping schemas (XSD)?
       >>>>
       >>>>Thanks.
       >>>>
       >>>>*** Sent via Developersdex
http://www.developersdex.com
       >>>***
       >>>>Don't just participate in USENET...get rewarded for it! .
       >>>>
       >>>.
       >>>
     >>.
     >>
  >.
Reply With Quote
  #6  
Old 03-19-02, 17:15
Clint
 
Posts: n/a
XML bulkload help

Ahh, sorry. I read it too quickly.

XML Spy is a great tool, but I usually only use it for XSL. While I have heard it has
the capability to export a database to an XDR, I currently use the SQL Server XML
View Mapper. It will take the database, and allow you to choose the tables you want
to map to an XDR schema. Very easy to use, and rumor has it that the next version
will much friendlier.

If you are importing relatively small xml documents(under 5 mb), I would use the
combination of an activex script and a stored procedure using the OpenXML function. I
believe that you can have BizTalk route a document to a port which can deliver the
document in a variety of ways (HTTP, file location, etc.) This would allow you to
write a script in ASP if you used the URL over HTTP method.

For large documents, I would create a job in SQL server. Write an activex script
giving the location of the xml document (have BizTalk place the file), then the
location of the XDR schema. You will have to use the SQLXMLBulkLoad object in this
script. But the script is easy to write.

Microsoft Products use the XDR (not XSD) for schema definitions, and probably will
for sometime (Correct me if you hear differently.)

Let me know if you have any questions on how to write your
XDR. Ill need a sample of your XML and your database layout. Also, how many records
are you typically going to insert?

Y. Field MCDBA

  >TEST--Original MessageTEST-- Clint,
  >
  >Thanks for the info. But again, I need to know does sqlxml suport ~XSD~ mappings.
  >XSD is the w3c standard, not the microsoft standard. I am using XML Spy to help
me
  >write these mappings and the export from my SQLdatabase comes in as an XSD schema.
  >When I convert it to XDR, I lose the sql namesspace support. I really like XML spy
  >for what it is doing (and already paid my $500).
  >
  >If not, do you know of any tool that does an export of an existing database to an
  >XDR schema definition.
  >
  >Here is the bottom line. I am using BizTalk to import
xml
  >documents. I plan to use the Mapper to map from my input xml document to the
  >sqlxml schema map. Then do the XML Bulk upload from there. Is there a better way
  >to do this?
  >
  >Thanks again for your time.
Reply With Quote
  #7  
Old 03-19-02, 19:49
Dan Doris -Lsqms
 
Posts: n/a
Re: XML bulkload help

Both WR2 and WR3 support XSD. For converting the xdr -> xsd i would suggest using
cvtschema.exe provided with both WR2 and WR3. Sound like there is a limitation with
the tools you are currently using to do the conversion.

Dan Doris

This posting is provided "AS IS" with no warranties, and confers no rights. You
assume all risk for your use.

"Mike Weeder" <mweeder@truserv.com> wrote in message
news:4f4301c1cf6f$7af2b350$36ef2ecf@tkmsftngxa12...
  > Clint,
  >
  > Thanks for the info. But again, I need to know does sqlxml suport ~XSD~ mappings.
  > XSD is the w3c standard, not the microsoft standard. I am using XML Spy to help me
  > write these mappings and the export from my SQLdatabase comes in as an XSD schema.
  > When I convert it to XDR, I lose the sql namesspace support. I really like XML spy
  > for what it is doing (and already paid my $500).
  >
  > If not, do you know of any tool that does an export of an existing database to an
  > XDR schema definition.
  >
  > Here is the bottom line. I am using BizTalk to import xml documents. I plan to use
  > the Mapper to map from my input xml document to the sqlxml schema map. Then do the
  > XML Bulk upload from there. Is there a better way to do this?
  >
  > Thanks again for your time.
  >
  > /\/\ike
     > >TEST--Original MessageTEST-- Yep. I recently used a similar xdr to do a similar
     > >import. It works very well.
     > >
     > >I think this link may give some good info.
     > >http://msdn.microsoft.com/library/default.asp?
     > >url=/library/en-us/xmlsql/ac_mschema_78q1.asp
     > >
     > >Also, check out Graeme Malcolm's book
     > >
  > (http://www.microsoft.com/mspress/boo...178.asp#TableO
     > >fContents). Good examples of doing this.
     > >
     > >Cheers!
     > >
     > >>TEST--Original MessageTEST-- Clint,
     > >>
     > >>Looks to me that you gave an xdr mapping instead of an xsd. Does XML Bulk Load
     > >>support xsd?
     > >>
     > >>/\/\ike
     > >>
     > >>>TEST--Original MessageTEST-- Hello, Are you trying to get an idea on how to
     > >>>write your
     > >schema
     > >>>for this database layout?
     > >>>
     > >>>Here is a rough draft that will get you started:
     > >>>
     > >>><?xml version="1.0" ?> <Schema xmlns="urn.schemas-microsoft-com:xml-data"
     > >>>xmlns:dt="urn:schemas-microsoft-com:datatypes"
     > >>>xmlns:sql="urn:schemas-microsoft-com:xml-sql" >
     > >>>
     > >>><ElementType name="topelement" sql:is-constant="1"> <element type="word" />
     > >>></ElementType>
     > >>>
     > >>><ElementType name="word" sql:relation="Words"> <AttributeType name="text" />
     > >>><attribute type="text" sql:field="word_text" />
     > >>>
     > >>> <element type="match"> <sql:relationship key-relation="word" key="matchID"
     > >>> foreign-key="matchID" foreign-relation="matches" /> </element> </ElementType>
     > >>>
     > >>>
     > >>>Ive some assumptions about your database schema, but
     > >this
     > >>>should be a good starting point.
     > >>>
     > >>>Best of luck:
     > >>>C. Field MCDBA
     > >>>
     > >>>
     > >>>>TEST--Original MessageTEST-- Hi experts,
     > >>>>
     > >>>>I am trying to bulk load an xml doc that looks like
     > >this:
     > >>>>
     > >>>><topelement> <word text="ball"> <match matchID="1" /> <match matchID="1234" />
     > >>>><match matchID="56" /> ... </word> <word text="puck"> <match matchID="5643" />
     > >>>>... </word> ... </topelement>
     > >>>>
     > >>>>into a single table that has two columns: word_text
  > and
     > >>>match_id. It's
     > >>>>a one-to-many relationship of a word to many matches.
     > >>>How can I
     > >>>>implement this using SQLXML mapping schemas (XSD)?
     > >>>>
     > >>>>Thanks.
     > >>>>
     > >>>>*** Sent via Developersdex
  > http://www.developersdex.com
     > >>>***
     > >>>>Don't just participate in USENET...get rewarded for it! .
     > >>>>
     > >>>.
     > >>>
     > >>.
     > >>
     > >.
Reply With Quote
  #8  
Old 03-20-02, 11:04
Clint
 
Posts: n/a
Re: XML bulkload help

cvtschema.exe?

Sounds interesting. Any links that show usage of this?

Thanks!

  >TEST--Original MessageTEST-- Both WR2 and WR3 support XSD. For converting the xdr ->
xsd i would suggest
  >using cvtschema.exe provided with both WR2 and WR3.
Sound like there is a
  >limitation with the tools you are currently using to do
the conversion.
  >
  >
  > Dan Doris
Reply With Quote
  #9  
Old 03-21-02, 04:53
Dan Doris -Lsqms
 
Posts: n/a
Re: XML bulkload help

There are instructions in the help file for either WR2 and WR3.

dan

"Clint" <me@work.com> wrote in message
news:54ee01c1d00e$bd864f20$36ef2ecf@tkmsftngxa12...
  > cvtschema.exe?
  >
  > Sounds interesting. Any links that show usage of this?
  >
  > Thanks!
  >
     > >TEST--Original MessageTEST-- Both WR2 and WR3 support XSD. For converting
     > >the xdr ->
  > xsd i would suggest
     > >using cvtschema.exe provided with both WR2 and WR3.
  > Sound like there is a
     > >limitation with the tools you are currently using to do
  > the conversion.
     > >
     > >
     > > Dan Doris
Reply With Quote
  #10  
Old 03-26-02, 09:30
Drew Minkin
 
Posts: n/a
RE: XML bulkload help

Rona,

What you are really asking is whether or not the sql:relationship element supports
one to many relationships when there is no constraint on the table to enforce that
either defines a primary or foreign key. If you trace a Bulk Load using
sql:relationship, you will see it runs sp_foreign_keys_rowset to determine if there
are such constraints. Simply put, you can do self joins using views and the
sql_relationship without formal keys, but bulk load requires them.

Investigate using XSLT to change the structure and iteratively add attributes with
the parent key information or consider using OPENXML as follows:

DECLARE @idoc int DECLARE @doc varchar(1000) SET @doc ='<topelement> <word
text="ball"> <match matchID="1" /> <match matchID="1234" /> <match matchID="56" />
</word> <word text="puck"> <match matchID="5643" /> </word> </topelement>' --Create
an internal representation of the XML document. EXEC sp_xml_preparedocument @idoc
OUTPUT, @doc -- Execute a SELECT statement that uses the OPENXML rowset provider.

INSERT INTO #temptable

SELECT * FROM OPENXML (@idoc, '/topelement/word/match',8) WITH ( text varchar(10)
'parent::word/@text' , ID int '@matchID' )

EXEC sp_xml_removedocument @idoc

Thank you for your post and I hope you found the information helpful.

Drew Minkin, MCDBA, MCSD, MCSE SQL Support Professional, Microsoft Corporation email:
dminkin@online.microsoft.com

This posting is provide "AS IS" with no warranties, and confers no rights. Please do
not send email directly to this alias. Respond to the newsgroup

For the latest in SQLXML, check out http://www.microsoft.com/sql/techinfo/xml

Are you secure? For information about the Microsoft Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump