如果名稱空間在所有元素中都加上前綴,您將如何編寫t-sql查詢?我已經嘗試了許多變化,這是迄今爲止,但它只是不起作用...但T-SQL中的XML名稱空間
DECLARE @x xml
SET @x = (SELECT xml_data_column FROM dbo.Table
WHERE xmlFileName = 'E:\trnFile.xml' )
;WITH XMLNAMESPACES('http://schemas.xmlsoap.org/soap/envelope/' AS [soap]
, 'tns:RetrievePurchaseResponse xmlns:tns="urn:Transaction"' AS tns)
SELECT t.c.value('orderRef[1]', 'int') orderReference
, t.c.value('orderNumber[1]', 'varchar(100)') orderNumber
, t.c.value('subtotal[1]', 'varchar(100)') subtotal
FROM @x.nodes('/soap:Envelope/soap:Body/tns:RetrievePurchaseResponse/tns:purchase') AS t(c)
援助將不勝感激!
下面是XML輸入文件:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<tns:RetrievePurchaseResponse xmlns:tns="urn:Transaction">
<tns:purchase>
<tns:orderRef>10027</tns:orderRef>
<tns:orderNumber>425816</tns:orderNumber>
<tns:subtotal>95.00</tns:subtotal>
</tns:purchase>
</tns:RetrievePurchaseResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
預計產出將是
orderReference, orderNumber, orderUserEmail
10027, 425816, [email protected]
請發表你正在處理的XML的樣本和預期產出您使用該XML的查詢。 –
好的,我添加了它作爲參考 – brynn