Subject:Illegal XML characters Author:Bernard Quinn Date:14 Aug 2008 11:33 AM
I have an XQuery built which generates the XML I need from a relational db (MS SQL Server 2005). I ocassionally get an "illegal xml character" error that kills the pull. Since studio obviously recognizes the bad character, is there a way to filter them out on the fly? Shouldn't there be a simple "drop anything illegal" filter available somewhere?
Subject:Illegal XML characters Author:Minollo I. Date:21 Aug 2008 01:32 PM
 is indeed an invalid XML character. And there isn't a way to instruct the XQuery engine to skip/replace invalid XML character retrieved from the database.
Since you are using SQLServer 2005, you can try the following approach:
import module namespace ddtek-sql = "http://www.datadirect.com/xquery/sql-function" at "sqlfunctions_sqlserver.xq";
for $row in collection("MYTABLE")/MYTABLE
let $col := $row/column1
let $col := ddtek-sql:REPLACE($col, ddtek-sql:CHAR(xs:int(1)), "")
return $col
The sqlfunctions_sqlserver.xq can be found in the examples/ExternalFunctions directory of your DataDirect XQuery installation (or in <stylusstudiodir>\Components\DataDirect XQuery\examples" in a typical Stylus Studio installation).
For multiple illegal characters you could do:
import module namespace ddtek-sql = "http://www.datadirect.com/xquery/sql-function" at "sqlfunctions_sqlserver.xq";
for $row in collection("MYTABLE")/MYTABLE
let $col := $row/column1
let $col := ddtek-sql:REPLACE($col, ddtek-sql:CHAR(xs:int(1)), "")
let $col := ddtek-sql:REPLACE($col, ddtek-sql:CHAR(xs:int(2)), "")
return $col