2015-01-14 31 views
0

我有一些MariaDB數據庫上的XML數據,需要做一些解析。 我已經嘗試使用下面的代碼extraxt一些值,但不管是什麼我可以嘗試我不斷收到null作爲輸出MySQL/MariaDB命名空間xml返回null與ExtractValue

SELECT xmlResponse FROM myDataBase.xmlLogging where id = '1' INTO @xml; 
SELECT ExtractValue(@xml, 'node2'); 

也試圖count(node2),試圖確定是否有在我syntaxaccording somtheting不對本

https://mariadb.com/kb/en/mariadb/documentation/sql-structure-and-commands/functions-and-operators/string-functions/extractvalue/

我的XML結構看起來像這樣,與namespacess

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
<SOAP-ENV:Body> 
<ns:SMnamespace xmlns:ns="http://somenamespace.com/WS/"> 
<ns:Error_spcCode>0</ns:Error_spcCode><ns:Error_spcMessage/> 
<ListofData xmlns="http://www.vendor.com/namespeceIO"> 
    <node1> 
     <node2>text</node2> 
     <node3>text</node3> 
     <node4/> 
    </node1> 
</ListofData> 
</ns:SMnamespace> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope>' 

回答

2

MySQL/MariaDB不支持xml命名空間。但是,它們在元素名稱中支持冒號。

,你沒有得到的節點應該是無效的情況下在你的位置路徑嘗試理由:

SELECT ExtractValue(@xml, '//node2');

開始與// XPath表達式意味着文檔中的任何節點。

+0

即使在XPath表達式中,我也會得到null,但是我猜如果命名空間不被支持,它可能會證明返回null的原因 – nikolas

1

我發現這個參考

http://bugs.mysql.com/bug.php?id=51425

,似乎這是對我的情況也是如此。我演示的這個xml是我的實際包含相當大的字符串的簡化版本。所以,只要我縮小了字符串的大小,我就可以得到結果。