Home > Archive > MS SQL XML > October 2005 > SQLXML bulk load and Base64 data









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SQLXML bulk load and Base64 data
Igor V. Derbyshev

2005-10-27, 9:25 am

Hi.
I'm trying to bulk load XML data with SQLXML 3.0.
XML file has base64 encoded field which corresponds to Image datatype column
in database.
But I get the following error:

Invalid character value for cast specification.

When I leave base64 attribute empty, everything is ok.
What is wrong?

XSD Schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:dt="urn:schemas-microsoft-com:datatypes"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xsd:annotation>
<xsd:appinfo>
<sql:relationship name="OrderOD"
parent="Ord"
parent-key="OrderID"
child="OrderDetail"
child-key="OrderID" />

<sql:relationship name="ODProduct"
parent="OrderDetail"
parent-key="ProductID"
child="Product"
child-key="ProductID"
inverse="true"/>
</xsd:appinfo>
</xsd:annotation>

<xsd:element name="Order" sql:relation="Ord"
sql:key-fields="OrderID" >
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Product" sql:relation="Product"
sql:key-fields="ProductID"
sql:relationship="OrderOD ODProduct">
<xsd:complexType>
<xsd:attribute name="ProductID" type="xsd:int" />
<xsd:attribute name="ProductName" type="xsd:string" />
<xsd:attribute name="Data" dt:type="bin.base64"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="OrderID" type="xsd:integer" />
<xsd:attribute name="CustomerID" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>

XML file:

<ROOT>
<Order OrderID="11" CustomerID="ALFKI">
<Product ProductID="11" ProductName="Chai" Data="VGVzdA=="/>
<Product ProductID="22" ProductName="Chang" Data=""/>
</Order>
<Order OrderID="22" CustomerID="ANATR">
<Product ProductID="33" ProductName="Aniseed Syrup" Data=""/>
<Product ProductID="44" ProductName="Gumbo Mix" Data=""/>
</Order>
</ROOT>

Please help.



Igor V. Derbyshev

2005-10-27, 9:25 am

Problem solved.

Instead of
dt:type="bin.base64"
one should use
type="xsd:base64Binary"


"Igor V. Derbyshev" <derbyshev@mail.ru> wrote in message
news:egRfQRDyFHA.3152@TK2MSFTNGP10.phx.gbl...
> Hi.
> I'm trying to bulk load XML data with SQLXML 3.0.
> XML file has base64 encoded field which corresponds to Image datatype
> column
> in database.
> But I get the following error:
>
> Invalid character value for cast specification.
>
> When I leave base64 attribute empty, everything is ok.
> What is wrong?
>
> XSD Schema:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:dt="urn:schemas-microsoft-com:datatypes"
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> <xsd:annotation>
> <xsd:appinfo>
> <sql:relationship name="OrderOD"
> parent="Ord"
> parent-key="OrderID"
> child="OrderDetail"
> child-key="OrderID" />
>
> <sql:relationship name="ODProduct"
> parent="OrderDetail"
> parent-key="ProductID"
> child="Product"
> child-key="ProductID"
> inverse="true"/>
> </xsd:appinfo>
> </xsd:annotation>
>
> <xsd:element name="Order" sql:relation="Ord"
> sql:key-fields="OrderID" >
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="Product" sql:relation="Product"
> sql:key-fields="ProductID"
> sql:relationship="OrderOD ODProduct">
> <xsd:complexType>
> <xsd:attribute name="ProductID" type="xsd:int" />
> <xsd:attribute name="ProductName" type="xsd:string" />
> <xsd:attribute name="Data" dt:type="bin.base64"/>
> </xsd:complexType>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="OrderID" type="xsd:integer" />
> <xsd:attribute name="CustomerID" type="xsd:string" />
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
>
> XML file:
>
> <ROOT>
> <Order OrderID="11" CustomerID="ALFKI">
> <Product ProductID="11" ProductName="Chai" Data="VGVzdA=="/>
> <Product ProductID="22" ProductName="Chang" Data=""/>
> </Order>
> <Order OrderID="22" CustomerID="ANATR">
> <Product ProductID="33" ProductName="Aniseed Syrup" Data=""/>
> <Product ProductID="44" ProductName="Gumbo Mix" Data=""/>
> </Order>
> </ROOT>
>
> Please help.
>
>
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com