In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to export the table to XML format directly through SQL statement". In daily operation, I believe that many people have doubts about how to export the table to XML format directly through SQL statement. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to export the table to XML format directly through SQL sentence". Next, please follow the editor to study!
First, create a table:
The copy code is as follows:
USE [ip] GO / * object: Table [dbo]. [SiteData] script date: 09 go 11, 2010 17:41:11 * / SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo]. [SiteData] ([id] [int] IDENTITY (1) NOT NULL, [SiteName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL [SiteAdd] [varchar] COLLATE Chinese_PRC_CI_AS NOT NULL, [BaiduSort] [int] NOT NULL CONSTRAINT [DF_SiteData_BaiduSort] DEFAULT ((0)), [BaiduShouLu] [int] NOT NULL CONSTRAINT [DF_SiteData_BaiduShouLu] DEFAULT ((0)), CONSTRAINT [PK_SiteData] PRIMARY KEY CLUSTERED ([id] ASC) WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] GO SET ANSI_PADDING OFF
The data in the table is as follows:
The fields in the table are: number, website name, website address, Baidu ranking, Baidu included.
Now let's export the table directly to XML format with the following SQL statement:
The copy code is as follows:
SELECT 1 AS Tag, NULL AS Parent, SiteName AS [site!1! Website name], SiteAdd AS [sitebasket 1! Website address], BaiduSort AS [sitebasket 1! Baidu ranking], BaiduShouLu AS [sitebasket 1! Included in Baidu] FROM SiteData order by BaiduShouLu FOR XML EXPLICIT
After running this statement, we can see the following in the running result of SQL Server2005:
We can see that the content of this XML node can be customized in SQL and distance. at this time, as long as we click on the output, we can export a piece of code in XML format.
We will get: copy the code as follows:
The XML code we get now does not contain the header and encoding format of XML. If we want to be more stupid, we can directly customize and add the following content in the background: copy the code as follows:
/ / content is the string string content = content.Replace ("") obtained after we read the database; / / Custom XML encoding format and parent node name content = "" + content + "/ / output XML to the local path using (StreamWriter sw = new StreamWriter (@" E:\ SoftUpdate\ sql2xml.xml ")) {sw.Write (content);}
At this point, the study on "how to export the table to XML format directly through SQL statement" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.