XML Parsing Issue

  • I am looking something like this from XML file to table

    like attached text file for xml

    In database table I want to parse like

    COL1 COL2

    EmployeeID EID1564654

    EmployeeName ABC

    EmployeeTitle XYZ

    City NY

    How can I parse values from XML files ?:crazy:

  • And the version of the SQL server is ...?

    And files are located where... (filesystem, stored in DB)?

  • I attached file because I can't write XML code here. It wont show. XML code is passing as a XMLdocument.

    & SQL 2005/2008

    Thanks,

  • -- Import the file into an XML variable

    declare @xmlimportdata xml

    SELECT @xmlimportdata = xmldata

    FROM

    (

    SELECT *

    FROM OPENROWSET (BULK 'filename.xml' , SINGLE_BLOB) AS XMLDATA

    ) AS FileImport (XMLDATA)

    -- convert XML to table

    SELECT node.query('fn:local-name(.)') AS NodeName, node.query('./text()') AS NodeValue into #t

    FROM @xmlimportdata.nodes(N'//*') T(node);

    select * from #t

    drop table #t

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply