SQL Server extracts the node data from the XML file into the database

Source: Internet
Author: User

Source: http://blog.csdn.net/kk185800961/article/details/12350715 Reprint Please specify the source

XML instance file:
  1. <? XML version="1.0" encoding="Utf-8" ?>
  2. <!--edited with XMLSpy v2010 (http://www.altova.com) by Fengshuai (founder)-   
  3. < Root >   
  4. < Frame >   
  5. < Item >   
  6. < ID > 0 </ ID >   
  7. < Num > 1 </ Num >   
  8. < rs_rate > (240,240) </ rs_rate >   
  9. < Mode > AA </ Mode >   
  10. < Rate > the </ Rate >   
  11. < modulation > BPSK </ modulation >   
  12. < Type > Design </ Type >   
  13. </ Item >   
  14. < Item >   
  15. < ID > 1 </ ID >   
  16. < Num > 2 </ Num >   
  17. < rs_rate > (240,192) </ rs_rate >   
  18. < Mode > KK </ Mode >   
  19. < Rate > the </ Rate >   
  20. < modulation > QPSK </ modulation >   
  21. < Type > Personality </ Type >   
  22. </ Item >   
  23. </ Frame >   
  24. < Config >   
  25. < Service >   
  26. < Service_item >   
  27. < SID > 254 </ SID >   
  28. < MID > 1 </ MID >   
  29. < Mode > GG </ Mode >   
  30. < Band > 27648 </ Band >   
  31. < isscramble > false </ isscramble >   
  32. </ Service_item >   
  33. </ Service >   
  34. </ Config >   
  35. </ Root >   

--More references (openrowset,sp_xml_preparedocument)

SQL statements:

  1. DECLARE @idoc int   
  2. DECLARE @xml XML
  3. SELECT @xml =bulkcolumn from OPENROWSET (BULK ' F:\360Downloads\Apk\test.xml ', Single_blob) as x
  4. SELECT @xml
  5. EXEC sp_xml_preparedocument @Idoc OUTPUT , @xml
  6. SELECT  *  into  # Temp from OPENXML (@Idoc, '/root/frame/item ', 2)
  7. with  (  
  8. ID INT
  9. , Num INT
  10. , rs_rate varchar(TEN)
  11. , Mode varchar(TEN)
  12. , rate varchar(TEN)
  13. , modulation varchar(TEN)
  14. , Type varchar(TEN)
  15. )
  16. Select  *  from  # Temp   
  17. Drop table # temp



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.