473,395 Members | 1,595 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,395 software developers and data experts.

How to append header to XML file generated using BCP in SQL

I am generating XML files using FOR XML AUTO, ELEMENTS with BCP in SQL Query. When I try to open an the XML file in browser, I get an error that "Only one Top level element is allowed in an XML document". I am assuming the XML document is missing the header line <?xml version="1.0" ........etc etc.

How do I append this header to the XML file in the run time ?

Images of Error, XML in Notepad, and typical Table I would to create from XML.
http://www.fiu.edu/~atmakurk/kk/XML_Error.jpg
http://www.fiu.edu/~atmakurk/kk/XML_View.jpg
http://www.fiu.edu/~atmakurk/kk/Table_View1.jpg

The SQL Query I am using is below:

Declare @SQuery nvarchar(3000)

Set @SQuery = 'bcp "EXEC test..free_CustomsDistrict_HS4_TEST [2006exp], 21, 6, 2" QueryOut "' + @fName + '" -c -t, -T'

Exec master..xp_cmdshell @SQuery



I am a new to XML and also newbie programmer. What I am really trying to do with the XML files is to display them as tables in webpages.
I would appreciate if anyone can direct me how to proceed ? How do I retrevie the XML file from Front End (ASP.NET) ?
Aug 31 '07 #1
2 4712
jkmyoung
2,057 Expert 2GB
What the error refers to is not having a root element. Eg, the following would be invalid as an xml document:
Expand|Select|Wrap|Line Numbers
  1. <row>
  2.   <value>1</value>
  3. </row>
  4. <row>
  5.   <value>2</value>
  6. </row>
You'd need to wrap these elements in a root element like so:
Expand|Select|Wrap|Line Numbers
  1. <table><row>
  2.   <value>1</value>
  3. </row>
  4. <row>
  5.   <value>2</value>
  6. </row>
  7. </table>
You have multiple d elements at the root level.
Aug 31 '07 #2
I fixed the problem by adding ROOT option in the FOR XML part.
Aug 31 '07 #3

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

Similar topics

16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
4
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: Lauchlan M | last post by:
Hi. I have an ASP.net project that works fine. I copied it to another project using the following steps: << (i) create a new VS.NET ASP.NET project.
0
by: Daniel Thune, MCSE | last post by:
I am having a problem with formatting a SOAP Header in a .Net client. The client calls a Java Axis 1.1 based web service. In order to authenticate the caller, the web service call is intercepted by...
1
by: Greg | last post by:
Hi, In a C++/CLR Windows Forms app I notice that there is only a header and no ..cpp for the form. Also event handler bodies are added by the IDE right to the header. What is the philosophy...
12
by: vj | last post by:
I am using Borland C++. I run a program which generates output data files, say 'Voltage.dat', 'Current.dat'. I have a variable in my code (say N), and for various values of N (for each value of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.