none
Forward Slash in Field Names FOR XML AUTO RRS feed

  • Question

  • We are using FOR XML AUTO to convert the output of a proc into XML for post processing in code. One interesting case is where the field name we return contains a forward slash. For example, the following select (from any arbitrary table):

    SELECT 'B' AS [B/S] FROM TABLS FOR XML AUTO

    Returns XML like:

    <p B_x002F_S="B"/><p B_x002F_S="B"/>

    the field name B/S has been replaced by B_x002F_S.

    Is there any way of changing this behaviour and getting the genuine field name (B/S) into the XML?

    Friday, May 10, 2013 9:39 AM

Answers

All replies

  • Hello,

    by XML specification a slash in a tag / element name is not allowed, therefore SQL replaces slashes by there XML encoding.


    Olaf Helper

    Blog Xing

    Friday, May 10, 2013 9:45 AM
  • Thanks, I'll change the post-processing code to do the right thing and reverse the XML encoding before passing the data on.

    (for reference, this is easy in C#, just use XmlConvert.DecodeName passing in the attribute name to reverse the encoding).

     - Richard

    Friday, May 10, 2013 9:58 AM