Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XML General > SQL and XML

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-2008, 08:55 PM
Mike Stokan
 
Posts: n/a

Default newbie - parse filepath field into xml doc



I have a SQL 2005 table that stores filenames with attached path. Could
someone point me to a way to parse the path/filename into an XML hierarchy?

Many thanks.

mike


Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-05-2008, 01:39 PM
Bob
 
Posts: n/a

Default RE: newbie - parse filepath field into xml doc

Just a quick note about the script, the

-- Parse them out into separate components
-- drive, folder1, folder2, full filename, filename only, extension

comment at the bottom was actually a TODO, not what the script really does ...

"Bob" wrote:

> This is a rough example but hopefully you get the idea:
>
> USE master
> GO
>
> -- Modified from
> http://www.microsoft.com/communities...xp=&sloc=en-us
> IF EXISTS (SELECT * FROM sys.objects WHERE object_id =
> OBJECT_ID(N'dbo.Split') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
> DROP FUNCTION dbo.Split
> GO
>
> CREATE FUNCTION dbo.Split
> (
> @str VARCHAR(MAX),
> @separator VARCHAR(MAX)
> )
> RETURNS @tableOutput TABLE ( row_id INT IDENTITY PRIMARY KEY, result
> VARCHAR(MAX))
> AS
> BEGIN
> DECLARE @xml XML;
>
> SET @xml = CAST( '<tag>' + REPLACE( @str, @separator,'</tag><tag>' ) +
> '</tag>' AS XML )
>
> INSERT @tableOutput ( result )
> SELECT T.i.value('.', 'VARCHAR(255)') result
> FROM @xml.nodes('tag') T(i);
>
> RETURN
> END
> GO
>
> USE tempdb
> GO
>
> DROP TABLE #tmp
> CREATE TABLE #tmp( file_id INT IDENTITY UNIQUE, filepath VARCHAR(255)
> PRIMARY KEY )
> GO
>
> INSERT INTO #tmp VALUES ( 'c:\temp\' )
> INSERT INTO #tmp VALUES ( 'c:\temp\temp.txt' )
> INSERT INTO #tmp VALUES ( 'c:\temp\temp2\temp.csv' )
> GO
>
> -- Parse them out into separate components
> -- drive, folder1, folder2, full filename, filename only, extension
> SELECT file_id, result AS filepath_element
> FROM #tmp t
> CROSS APPLY master.dbo.Split( t.filepath, '\' )
> FOR XML RAW
> GO
>
> HTH
> wBob
>
> "Mike Stokan" wrote:
>
> > I have a SQL 2005 table that stores filenames with attached path. Could
> > someone point me to a way to parse the path/filename into an XML hierarchy?
> >
> > Many thanks.
> >
> > mike
> >
> >
> >

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 01:40 PM.
Style Developed by Epic Designz