?
Solved

Loading Document Declarion (1st line) of XML file into a data table using Bulk Load??

Posted on 2007-07-23
2
Medium Priority
?
238 Views
Last Modified: 2010-04-15
This question pertains to XML and SQL bulk load

Hello,

I am using Bulk Load to process an XML document into a SQL table. This works fine to get all the elements into the table except the document declaration (?xml version="1.0" encoding="utf-8" standalone="yes"). I must trim this off manually before the sproc below will run.

Question?? Is it possible to load the declaration statement ?xml version="1.0" encoding="utf-8" standalone="yes" into the data table as well intyo a varchar or nvarchar column??

XML file snippet:
<?xml version="1.0" encoding="utf-8" standalone="yes"?><Head><Num><a>11</a><b>37</b><c>07/01/2007</c></Num></Head>


SPROC processing XML elemants with Bulk Load:

DECLARE @docHandle int, @OID int
EXEC sp_xml_preparedocument @docHandle OUTPUT,  @order
BEGIN TRANSACTION
--Processing elements from XML file
INSERT INTO ObsDataTemp (a, b,c)
SELECT a, b,c  
 FROM OpenXml( @docHandle, '/Haul/ObsTowNum', 2)   WITH
  ( a int, b int,c smalldatetime )
  IF @@ERROR<>0 BEGIN ROLLBACK TRANSACTION RETURN -101 END
COMMIT TRANSACTION
EXEC sp_xml_removedocument @docHandle SELECT @OID AS [ReportID]
GO

I only want to load the declaration into the data table so the sproc will run and process the rest of the file with out manual intervention.

Thanks,
Sax
Translate:Authored by: Saxitalis
0
Comment
Question by:Saxitalis
2 Comments
 
LVL 9

Accepted Solution

by:
BurntSky earned 2000 total points
ID: 19567414
This question is posted in the C# section, so I assume you're calling this stored procedure from a C# application.  If so, you can strip out the document declaration before you pass the XML string to the stored procedure.  Here's one example:

XmlDocument doc = new XmlDocument();
doc.Load("your xml doc here");
string xmlForSproc = doc.DocumentElement.OuterXml;
0
 

Author Comment

by:Saxitalis
ID: 19610806
That is exactly what I am doing and that is the exact solutio!

Thank you very much!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question