需要一点帮助才能在 SQL Server 中创建一些 XML。
生成的 XML 应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Root Version="2.17" KFZ="XX-DD 389">
<Head name="ExecuteAnswer">
<Key name="AnswerStatus" value="-OK" />
<Key name="MsgId"><![CDATA[KFHB0907896aAUH223]]></Key>
<Section name="Command">
<Key name="Name" value="SetNewCommand" />
<Key name="Param0"><![CDATA[XX-DD 389]]></Key>
<Key name="Param1"><![CDATA[]]></Key>
<Key name="Param2"><![CDATA[0987asfdsafhdsSS]]></Key>
<Key name="Param3"><![CDATA[0097aSSSHSDOPir0]]></Key>
</Section>
</Head>
<Data></Data>
</Root>
我被困在添加<Section>
到 XML 中,如果我添加它,[Section!3!name]
我得到这个错误:
错误 -> 键将被部分覆盖
代码:
SELECT
1 AS Tag,
NULL AS Parent,
'2.17' AS [Root!1!Version],
'XX-DD 389' AS [Root!1!KFZ],
NULL AS [Head!2!name!Element],
NULL AS [Key!3!name],
NULL AS [Key!3!value],
NULL AS [Key!3!CDATA]
UNION ALL
SELECT
2 as Tag,
1 as Parent,
NULL,
NULL,
'ExecuteAnswer',
NULL,
NULL,
NULL
UNION ALL
SELECT
3 as Tag,
2 as Parent,
NULL,
NULL,
NULL,
'AnswerStatus',
'-OK',
NULL
UNION ALL
SELECT
3 as Tag,
2 as Parent,
NULL,
NULL,
NULL,
'MsgId',
NULL,
'KFHB0907896aAUH223'
FOR XML EXPLICIT
有人可以帮我吗?
问候亚历克斯