简体   繁体   中英

GML structure and SQL Server

I need to convert entire SQL Server view(s) into GML file. I partly succeed, but there is maybe some simpler way (my way is not simple definitely). I have this at the moment:

WITH XMLNAMESPACES ('www._.com' AS fgu, 'http://www.opengis.net/gml' as gml)
SELECT *
FROM [vParcela] as [fgu:attName]
FOR XML PATH('fgu:Parcela'), ROOT('gml:featureMember')

and getting something like:

<gml:featureMember xmlns:gml="http://www.opengis.net/gml" xmlns:fgu="www._.com">
  <fgu:Parcela>
    <lwr>6437356.24 4949868.47</lwr>
    <upp>6437368.53 4949878.06</upp>
    <oid>6158487618342</oid>
    <lineage_Parent>6158487458742</lineage_Parent>

I need to get prefix tags for every view's column (eg fgu:lwr, fgu:upp ...).

Is there a way to do this with select * and not defining all column names? And, againg, is there other way to export entire view(s) into one gml file at once (create single GML file from DB with complete gml structure)?

EDIT: Without software like FME , or other commercial.

It seems the only EASY way is to use columns names SELECT lwr as [fgu:lwr], ... .

Also you can try to use REPLACE() to do it:

WITH XMLNAMESPACES ('www._.com' AS fgu, 'http://www.opengis.net/gml' as gml)
SELECT 
    REPLACE(
    REPLACE(
    REPLACE(
    REPLACE(
    REPLACE(      
(SELECT *
     FROM [vParcela] as [fgu:attName]
     FOR XML PATH('Parcela'),ROOT('featureMember')
 ) 
    ,'</','</fgu:')  
    ,'<','<fgu:')
    ,'<fgu:/','</')
    ,'<fgu:featureMember','<gml:featureMember')
    ,'</fgu:featureMember','</gml:featureMember')

SQLFiddle demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM