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

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

17
I have a xml similar like this:

<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>


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:

CREATE PROCEDURE sp_insert_RefundCorrectionAcceptance AS

DECLARE @iTree int
DECLARE @xmlFile VARCHAR(2000)

EXEC sp_xml_preparedocument @iTree OUTPUT, @xmlFile,
SELECT *
FROM OPENXML (@iTree,'root', 3)
WITH (
MemberID decimal '/Member/@ID',
DateBorrowed datetime 'DateBorrowed/text()',
BookID decimal '/book/@id',
bookTitle varchar(200) '/book/@title',
bookCat varchar(100) '/book/category/text()'

)
EXEC sp_xml_removedocument @iTree
GO


Thank you.
Apr 5 '07 #1
1 2413
iburyak
1,017 Expert 512MB
Try this:


1. Create procedure:

[PHP]CREATE PROCEDURE sp_insert_RefundCorrectionAcceptance
@xmlFile VARCHAR(2000)
AS

DECLARE @iTree int

EXEC sp_xml_preparedocument @iTree OUTPUT, @xmlFile
SELECT *
FROM OPENXML (@iTree,'Member/Book',8)
WITH (
MemberID decimal '../@ID',
DateBorrowed datetime '../DateBorrowed/text()',
BookID decimal '@ID',
bookTitle varchar(200) '@Title',
bookCat varchar(100) 'Category/text()'

)
EXEC sp_xml_removedocument @iTree
GO[/PHP]

2. Execute procedure:

[PHP]sp_insert_RefundCorrectionAcceptance
'
<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>
'[/PHP]

Don't forget that XML is case sensitive.

Hope it helps.

Good Luck.

Irina.
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: Peri | last post by:
Dear All, I am developing 2 applications. The first application will keep on generate a new file in a span of 30 milliseconds with some valid data inside (This code is written in C). The...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.