开发者

Is the XML datatype transmitted as binary xml representation?

Is XMLDATA transmitted开发者_开发问答 as binary xml dom representation, or as an xml string?, when accessed with command.ExecuteXmlReader()?

A documentation link would be perfect.

What serialization/deserialization steps involved on the sql server and client side?

UPDATE:

The question is not about how to use the classes provided by net framework.

It's about the internal details of data transmission during execution of an Adonet command on an SQL Server connection, resulting in an XMLDATA column in a resultset.


OK, this is quite fun. I didn't find any reference, but I did do a quick trace with WireShark.

The format is some sort of internal representation, presumably a tree structure. The following value:

<ErrorData>
  <Error>The provided value for ItemCode contains invalid characters (_).</Error>
</ErrorData>

comes across the wire like this:

00c0   b0 04 f0 09 45 00 72 00 72 00 6f 00 72 00 44 00  ....E.r.r.o.r.D.
00d0   61 00 74 00 61 00 ef 00 00 01 f8 01 f0 05 45 00  a.t.a.........E.
00e0   72 00 72 00 6f 00 72 00 ef 00 00 02 f8 02 11 40  r.r.o.r........@
00f0   54 00 68 00 65 00 20 00 70 00 72 00 6f 00 76 00  T.h.e. .p.r.o.v.
0100   69 00 64 00 65 00 64 00 20 00 76 00 61 00 6c 00  i.d.e.d. .v.a.l.
0110   75 00 65 00 20 00 66 00 6f 00 72 00 20 00 49 00  u.e. .f.o.r. .I.
0120   74 00 65 00 6d 00 43 00 6f 00 64 00 65 00 20 00  t.e.m.C.o.d.e. .
0130   63 00 6f 00 6e 00 74 00 61 00 69 00 6e 00 73 00  c.o.n.t.a.i.n.s.
0140   20 00 69 00 6e 00 76 00 61 00 6c 00 69 00 64 00   .i.n.v.a.l.i.d.
0150   20 00 63 00 68 00 61 00 72 00 61 00 63 00 74 00   .c.h.a.r.a.c.t.
0160   65 00 72 00 73 00 20 00 28 00 5f 00 29 00 2e 00  e.r.s. .(._.)...
0170   f7 f7 00 00 00 00 d1 0d 27 00 00 02 00 00 00 01  ........'.......

Notes:

  • The tag names are included as (unicode) text, but they are included only once at opening, not at open and close.
  • Text node content is included as unicode text
  • In the binary stream extract attached, I don't have a clear picture of where the data actually starts, so it's hard to make good guesses about the format.

UPDATE: hey, cool, found it. I forgot the format is called TDS: http://www.freetds.org/tds.html#login7. It looks like you can specify whether Xml will be returned in binary format or not, depending on whether it's being passed to ADO or not.

Doc for Binary Xml: http://msdn.microsoft.com/en-us/library/ee208875.aspx


It returns a XmlReader object. Though getting the string representation from the object would be trivial.

http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx

Here's a good link that provides additional information about working with the class.

http://msdn.microsoft.com/en-us/library/9d83k261.aspx


There are three sample applications that demonstrate using the XML datatype in .NET available in the SQL Server Samples download at Codeplex. I believe you'll find them useful.

Once the samples are installed, have a look at the sample in the following folder: C:\Program Files\Microsoft SQL Server\100\Samples\Engine\XML\XmlManuInstructions

About halfway down the code file there's a demonstration how to retrieve XML as an XMLDocument object.

More info: Sample XML Applications at MSDN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜