views:

918

answers:

4

Is '' a valid piece of XML? Can '' insert into oracle xblob column or XML column from MSSQL?

+1  A: 

It's not valid xml. Valid xml requires an xml declaration with encoding type and a root node. Whether or not Oracle or SQL Server will accept it anyway is something you can check for yourself.

Joel Coehoorn
MSSQL column is fine with empty string and even a free text which is not in any XML style. I don't know how oracle to handle this. that is why I ask!
codemeit
The XML declaration is actually not a strict requirement for valid XML.
Joachim Sauer
+3  A: 

No. The spec says a well-formed XML document satisfies:

document ::=  prolog  element  Misc*

where

element ::= EmptyElemTag
              | STag content ETag
David Norman
+2  A: 

It's not an XML document - there needs to be at least one and at most one root element. (the XML declaration is optional if the encoding is UTF-8 and the version is 1.0 - production 22 of the XML recommendation). It is a valid XML fragment - either as an empty text node, or an empty range.

You'll have to define what 'piece of XML' means in your context.

Pete Kirkham
+3  A: 

It's not valid xml, but it can be inserted into an XML column in SQL Server 2005. I can't speak for Oracle, but I would almost be willing to bet it could.

Obviously with SQL Server 2005, you need to trade up the double quote for single quotes:

Insert Into MyTestTable(MyXmlColumn) Values('');

That works just fine - I just tested it and the insert was successful.

BenAlabaster
Don't you think this behavior from MSSQL 2005 is weired? Imagine you parse the data from that column to a XElement at dot net....
codemeit
@CodeMelt: That's Microsoft for you - there's lots weird about their products. If you wanted me to start a list of everything that was weird about MS products, I'd be here for eternity.
BenAlabaster