473,396 Members | 1,804 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 can I put this XML file into SQL Server...

Hi,

I have the following XML file:

<Message>

<MessageInfo MID="ODX95”></MessageInfo>
<Module>
<Invoice number="43562" inv_date="000000">
<Data>
<Name csg="ABC1"></Name>
<PartNumber code="123" quantity="96"></PartNumber>
<Price unit_price="13309.00" total_amount="1277664.00"></Price>
<PartNumber code="345" quantity="24"></PartNumber>
<Price unit_price="20213.00" total_amount="485112.00"></Price>
<PartNumber code="678" quantity="120"></PartNumber>
<Price unit_price="16593.00" total_amount="1991160.00"></Price>
<VAT amount="3753936.00" vat_rate="0.000"></VAT>
<Total total_amount="3753936.00" vat_amount="3753936.00"></Total>
</Data>
</Invoice>
</Module>

</Message>

What I want is that I want to put this data into SQL Table.

exec sp_xml_preparedocument @idoc OUTPUT, @doc
INSERT INTO #Invoices (DocumentNumber, InvoiceNumber, InvoiceDate, PartNumber, Quantity, Price)
SELECT * FROM OPENXML (@idoc, '/Message/Module/Invoice/Data/PartNumber', 1)
WITH (
DocumentNumber varchar(30) '../../../../MessageInfo/@MID',
InvoiceNumber varchar(30) '../../@number',
InvoiceDate varchar(30) '../../@invoice_date',
PartNumber varchar(30) '@code',
Quantity varchar(30) '@quantity',
Price varchar(30) '../Price/@unit_price'
)
EXEC sp_xml_removedocument @idoc


The result I get is the following...

DocumentNumber InvoiceNumber InvoiceDate PartNumber Quantity Price
ODX95 43562 000000 123 96 13309.00
ODX95 43562 000000 345 24 13309.00
ODX95 43562 000000 678 120 13309.00

I am getting always the same Price value. Why is that? And how can I avoid this???

Any ideas???

Thanks....
Oct 4 '07 #1
1 1423
azimmer
200 Expert 100+
Hi,

I have the following XML file:

<Message>

<MessageInfo MID="ODX95”></MessageInfo>
<Module>
<Invoice number="43562" inv_date="000000">
<Data>
<Name csg="ABC1"></Name>
<PartNumber code="123" quantity="96"></PartNumber>
<Price unit_price="13309.00" total_amount="1277664.00"></Price>
<PartNumber code="345" quantity="24"></PartNumber>
<Price unit_price="20213.00" total_amount="485112.00"></Price>
<PartNumber code="678" quantity="120"></PartNumber>
<Price unit_price="16593.00" total_amount="1991160.00"></Price>
<VAT amount="3753936.00" vat_rate="0.000"></VAT>
<Total total_amount="3753936.00" vat_amount="3753936.00"></Total>
</Data>
</Invoice>
</Module>

</Message>

What I want is that I want to put this data into SQL Table.

exec sp_xml_preparedocument @idoc OUTPUT, @doc
INSERT INTO #Invoices (DocumentNumber, InvoiceNumber, InvoiceDate, PartNumber, Quantity, Price)
SELECT * FROM OPENXML (@idoc, '/Message/Module/Invoice/Data/PartNumber', 1)
WITH (
DocumentNumber varchar(30) '../../../../MessageInfo/@MID',
InvoiceNumber varchar(30) '../../@number',
InvoiceDate varchar(30) '../../@invoice_date',
PartNumber varchar(30) '@code',
Quantity varchar(30) '@quantity',
Price varchar(30) '../Price/@unit_price'
)
EXEC sp_xml_removedocument @idoc


The result I get is the following...

DocumentNumber InvoiceNumber InvoiceDate PartNumber Quantity Price
ODX95 43562 000000 123 96 13309.00
ODX95 43562 000000 345 24 13309.00
ODX95 43562 000000 678 120 13309.00

I am getting always the same Price value. Why is that? And how can I avoid this???

Any ideas???

Thanks....
Hi, I guess you need two modifications:
1. Data set: I belive that the closing tag for <PartNumber> is misplaced, move them to behind each </Price> tags like this:
Expand|Select|Wrap|Line Numbers
  1. <PartNumber code="123" quantity="96">
  2. <Price unit_price="13309.00" total_amount="1277664.00"></Price></PartNumber>
  3. <PartNumber code="345" quantity="24">
  4. <Price unit_price="20213.00" total_amount="485112.00"></Price></PartNumber>
  5. <PartNumber code="678" quantity="120">
  6. <Price unit_price="16593.00" total_amount="1991160.00"></Price></PartNumber>
  7.  
2. change the SELECT to:
Expand|Select|Wrap|Line Numbers
  1. SELECT  * FROM OPENXML (@idoc, '/Message/Module/Invoice/Data/PartNumber', 1) 
  2. WITH (
  3. DocumentNumber varchar(30) '../../../../MessageInfo/@MID',
  4. InvoiceNumber varchar(30) '../../@number',
  5. InvoiceDate varchar(30) '../../@invoice_date', 
  6. PartNumber varchar(30) '@code',
  7. Quantity varchar(30) '@quantity', 
  8. Price varchar(30) 'Price/@unit_price'
  9. )
  10.  
(i.e. remove the '../' string from the 'Price' field).
Oct 5 '07 #2

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

Similar topics

20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.