473,408 Members | 2,813 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,408 software developers and data experts.

How to read second record within XML file by using openxml?

17
I have a xml similar like this:

[html]<Member ID="123">
<DateBorrowed>11-01-2006</DateBorrowed>
<Book ID="222"
Title="ABC">
<Category> Fiction</Category>
</Book>
<Book ID="333"
Title="ABu">
<Category>Children</Category>
</Book>
......
</Member>[/html]


I used OPENXML to read into MS SQL server database table, but it only reads first book. What should I do to read all three books, and insert 2 lines into the table:

MemberID | DateBorrowed | BookID | BookTitle | BookCategory
123 11-01-2006 222 ABC Fiction
123 11-01-2006 333 ABu Children
......

My code following only read first book:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE sp_insert_RefundCorrectionAcceptance  AS
  2.  
  3. DECLARE @iTree int
  4. DECLARE @xmlFile VARCHAR(2000)
  5.  
  6. EXEC sp_xml_preparedocument @iTree OUTPUT, @xmlFile,
  7. SELECT    *
  8. FROM  OPENXML (@iTree,'root', 3)
  9. WITH (
  10. MemberID decimal '/Member/@ID',
  11. DateBorrowed datetime 'DateBorrowed/text()',
  12. BookID decimal '/book/@id',
  13. bookTitle varchar(200) '/book/@title',
  14. bookCat varchar(100) '/book/category/text()'
  15.  
  16. )
  17. EXEC sp_xml_removedocument @iTree
  18. GO

Thank you.
Apr 5 '07 #1
1 2535
dorinbogdan
839 Expert 512MB
For your XML, I tested with this Select query:
Expand|Select|Wrap|Line Numbers
  1. SELECT    *
  2. FROM  OPENXML (@iTree,'Member/Book', 3)
  3. WITH (
  4. MemberID decimal '/Member/@ID',
  5. DateBorrowed datetime '../DateBorrowed/text()',
  6. BookID decimal '@ID',
  7. bookTitle varchar(200) '@Title',
  8. bookCat varchar(100) 'Category'
  9. )
  10.  
and it works.
Apr 5 '07 #2

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

Similar topics

6
by: Andrzej | last post by:
Used to read newsgroup for answers, now have to ask for them as well. I have an application (C#, .NET 1.1) that connects to local db on MSDE 2000 SP3a (using ADO from MDAC 2.71) on one side and...
1
by: Steven Blair | last post by:
Hi, Got a general query regarding XML and Databases. To be honest, I really don't kno that much about XML. Here is my problem: I have a XMl file containing a number of transactions in a...
6
by: G.Esmeijer | last post by:
Friends, I would like to read a text file (fixed length formaated) really fast and store the data into an Access database (2003). Using the streamreader and reading line by line, separating the...
2
by: Red2 | last post by:
Hi All, I am receiving a flat file data feed from another system. This is comming in every 10 minutes and is going to need to be a high permormance system. The file will contain all the data...
4
by: Pim75 | last post by:
Hello, I have to read a XML file in ASP and save the values in a database. I can get this work, but I cannot read some nested nodes of the xml file. This is a part of the XML file: ...
23
by: ShaneO | last post by:
Hello, I wish to extract embedded string data from a file using a Binary Read method. The following code sample is used in VB.NET and similar code is used in VB6 - (Assume variable...
1
by: yingwen | last post by:
I have a xml similar like this: <Member ID="123"> <DateBorrowed>11-01-2006</DateBorrowed> <Book ID="222" Title=""ABC"> <Category> Fiction</Category> </Book>...
0
by: drharris | last post by:
First, please forgive my newness to XML. I've used it to serialize/ deserialize objects, exporting and importing datasets, and other such things that pretty much automate reading in the file. I've...
2
by: shankar2 | last post by:
Hello All, This is my first try at posting a query in this forum, your patience is appreciated. App Details: Access 2000 on Win 2000, Slightly better than a Novice, comfortable with various...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.