Mysql 将SQL表导出到合并了标记的XML文件
我创建了一个SQL表,其中包含一大堆需要导出为XML的列,但XML需要采用特定的格式,而且我似乎无法让它看起来像是假定的:Mysql 将SQL表导出到合并了标记的XML文件,mysql,sql-server,xml,Mysql,Sql Server,Xml,我创建了一个SQL表,其中包含一大堆需要导出为XML的列,但XML需要采用特定的格式,而且我似乎无法让它看起来像是假定的: <a c1="aa" c2="ab"> <b c3="ac" c15="an"> <c c4="ad" c5="ae" c6="af" c7="ag" c8="ah" c9="ad"> <d c10="ai" c11="aj" c12="ak" c13="al">am</d>
<a c1="aa" c2="ab">
<b c3="ac" c15="an">
<c c4="ad" c5="ae" c6="af" c7="ag" c8="ah" c9="ad">
<d c10="ai" c11="aj" c12="ak" c13="al">am</d>
<d c10="bi" c11="bj" c12="bk" c13="bl">bm</d>
<d c10="ci" c11="cj" c12="ck" c13="cl">cm</d>
</c>
--Next item for c
<c>
<d></d>
<d></d>
<d></d>
</c>
</d>
---and so on and on`
这就产生了
<a c1="aa" c2="ab">
<b c3="ac" c15="an">
<c c4="ad" c5="ae" c6="af" c7="ag" c8="ah" c9="ad">
<d c10="ai" c11="aj" c12="ak" c13="al">am</d>
</c>
</b>
</a>
<a c1="ba" c2="bb">
<b c3="bc" c15="bn">
<c c4="bd" c5="be" c6="bf" c7="bg" c8="bh" c9="bd">
<d c10="bi" c11="bj" c12="bk" c13="bl">bm</d>
</c>
</b>
</a>
<a c1="ca" c2="cb">
<b c3="cc" c15="cn">
<c c4="cd" c5="ce" c6="cf" c7="cg" c8="ch" c9="cd">
<d c10="ci" c11="cj" c12="ck" c13="cl">cm</d>
</c>
</b>
</a>
是
bm
厘米
我尝试运行带有子选择的select(很抱歉,代码仍在运行,我记不起具体的操作方法),但b标记后的所有子项都会丢失格式(writes>而不是>)
再次感谢您抽出时间,非常感谢您的光临,
如果有人用类似的问题找到了这个问题,下面是我如何解决的,很遗憾,我没有时间将变量重命名为上面的示例:
(select
a1.CONTINENTID as '@id', a1.CONTINENTNAME as '@name',
(select a2.COUNTRYID as '@id', a2.COUNTRYNAME as '@name',
(select CENTREID as '@id', CENTRENAME as'@name', CENTRECODE as '@code',
CENTRELATITUDE as '@lat', CENTRELONGITUDE as '@lon', CENTRESTATUS as '@status',
(select HEADING as '@text', HEADINGSTATUS as '@status',
(select
HEADINGITEM as 'Collapsableheadingitem/@text',
HEADINGITEMSTATUS as 'Collapsableheadingitem/@status',
HEADINGITEMDESCRIPTION as 'Collapsableheadingitem'
From OIAUI as a5
where a5.HEADING = a4.HEADING and
a5.CENTREID = a3.CENTREID and
a5.COUNTRYID = a2.COUNTRYID and
a5.CONTINENTID = a1.CONTINENTID
GROUP BY a5.STATUSID, HEADINGITEM, HEADINGITEMSTATUS, HEADINGITEMDESCRIPTION
ORDER BY a5.STATUSID DESC
for xml path(''), type
)
FROM OIAUI as a4
WHERE a4.CENTREID = a3.CENTREID and
a4.COUNTRYID = a2.COUNTRYID and
a4.CONTINENTID = a1.CONTINENTID
GROUP by a4.HEADING, a4.HEADINGSTATUS
ORDER BY a4.HEADING
FOR XML PATH('Collapsableheading'), type
)
from OIAUI as a3
where a3.CONTINENTID = a1.CONTINENTID and
a3.COUNTRYID = a2.COUNTRYID
group by a3.CENTREID, a3.CENTRENAME, a3.CENTRECODE, a3.CENTRELATITUDE, a3.CENTRELONGITUDE, a3.CENTRESTATUS
ORDER BY a3.CENTREID
for xml path('CashCentre'), type
)
from OIAUI as a2
where a1.CONTINENTID = a2.CONTINENTID
group by a2.COUNTRYID, a2.COUNTRYNAME
ORDER BY a2.COUNTRYID
for xml path('Country'), type
)
from OIAUI as a1
group by CONTINENTID, CONTINENTNAME
ORDER BY a1.CONTINENTID
for xml path('Continent')
)
(select
a1.CONTINENTID as '@id', a1.CONTINENTNAME as '@name',
(select a2.COUNTRYID as '@id', a2.COUNTRYNAME as '@name',
(select CENTREID as '@id', CENTRENAME as'@name', CENTRECODE as '@code',
CENTRELATITUDE as '@lat', CENTRELONGITUDE as '@lon', CENTRESTATUS as '@status',
(select HEADING as '@text', HEADINGSTATUS as '@status',
(select
HEADINGITEM as 'Collapsableheadingitem/@text',
HEADINGITEMSTATUS as 'Collapsableheadingitem/@status',
HEADINGITEMDESCRIPTION as 'Collapsableheadingitem'
From OIAUI as a5
where a5.HEADING = a4.HEADING and
a5.CENTREID = a3.CENTREID and
a5.COUNTRYID = a2.COUNTRYID and
a5.CONTINENTID = a1.CONTINENTID
GROUP BY a5.STATUSID, HEADINGITEM, HEADINGITEMSTATUS, HEADINGITEMDESCRIPTION
ORDER BY a5.STATUSID DESC
for xml path(''), type
)
FROM OIAUI as a4
WHERE a4.CENTREID = a3.CENTREID and
a4.COUNTRYID = a2.COUNTRYID and
a4.CONTINENTID = a1.CONTINENTID
GROUP by a4.HEADING, a4.HEADINGSTATUS
ORDER BY a4.HEADING
FOR XML PATH('Collapsableheading'), type
)
from OIAUI as a3
where a3.CONTINENTID = a1.CONTINENTID and
a3.COUNTRYID = a2.COUNTRYID
group by a3.CENTREID, a3.CENTRENAME, a3.CENTRECODE, a3.CENTRELATITUDE, a3.CENTRELONGITUDE, a3.CENTRESTATUS
ORDER BY a3.CENTREID
for xml path('CashCentre'), type
)
from OIAUI as a2
where a1.CONTINENTID = a2.CONTINENTID
group by a2.COUNTRYID, a2.COUNTRYNAME
ORDER BY a2.COUNTRYID
for xml path('Country'), type
)
from OIAUI as a1
group by CONTINENTID, CONTINENTNAME
ORDER BY a1.CONTINENTID
for xml path('Continent')
)