Control chars in XML

  • Comments posted to this topic are about the item Control chars in XML



    See, understand, learn, try, use efficient
    © Dr.Plch

  • This is an excellent question, thank you. I thoroughly enjoyed it because I found it to be pretty difficult to answer correctly. I suspect that "most characters illegal" means all except the tab (char(9)), linefeed (char(10), 0xA), carriage return (char(13), 0xD) and the space(char(32) 0x20). I am curious to find out how the results of your

    select * from #t for xml auto;

    will look in SSMS results window, will definitely do it tomorrow morning.

    Oleg

  • hello frnds....

    wht ever it may be in order to run completely a block of t-sql code it should be syntax error free

    i think there is no += operator in database so the code itself is wrong and u cant even think of it running how can you expect us to post answer for it.......

    ;-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-)

  • Maddy...! (5/19/2010)


    hello frnds....

    wht ever it may be in order to run completely a block of t-sql code it should be syntax error free

    i think there is no += operator in database so the code itself is wrong and u cant even think of it running how can you expect us to post answer for it.......

    ;-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-);-)

    This code is valid!

    += operator is legal in the current version of SQL Server.

    I expect people to answer questions without running code. I know, I'm old enough to be so naive.



    See, understand, learn, try, use efficient
    © Dr.Plch

  • honza.mf (5/19/2010)


    Maddy...! (5/19/2010)


    hello frnds....

    wht ever it may be in order to run completely a block of t-sql code it should be syntax error free

    i think there is no += operator in database so the code itself is wrong and u cant even think of it running how can you expect us to post answer for it.......

    This code is valid!

    += operator is legal in the current version of SQL Server.

    I expect people to answer questions without running code. I know, I'm old enough to be so naive.

    You should specify which environment is used in the question. As a SQL 2005 user, I saw that there would be an error. You even don't have to run the code to see that.

    I cannot guess which environment you had in mind.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Hi,

    When I run this it will success fully executed.I changed it @i+=1 to @i=@i+1;

    but it will show result as with out using for xml.

    after for xml i executed but it opened on SSMS.But i saved it in the form XML.With IE i am unable to open.With for xml it shows in different.Please explain in detail abot this characters.but i understand that this char will return the value of the character.suppose char(65) will return A.but and also 32 is space i think.what are the charcters below 32.The result of sample data as shown below.

    <_x0023_t a="" />

    <_x0023_t a="&#x1;" />

    <_x0023_t a="&#x2;" />

    <_x0023_t a="&#x3;" />

    <_x0023_t a="&#x4;" />

    <_x0023_t a="&#x5;" />

    <_x0023_t a="&#x6;" />

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • da-zero (5/20/2010)


    You should specify which environment is used in the question. As a SQL 2005 user, I saw that there would be an error. You even don't have to run the code to see that.

    I cannot guess which environment you had in mind.

    This one question was on XML. Yes, you are right, the environment was not specified.



    See, understand, learn, try, use efficient
    © Dr.Plch

  • honza.mf (5/20/2010)


    da-zero (5/20/2010)


    You should specify which environment is used in the question. As a SQL 2005 user, I saw that there would be an error. You even don't have to run the code to see that.

    I cannot guess which environment you had in mind.

    This one question was on XML. Yes, you are right, the environment was not specified.

    Well, it could have been a trick question 😉 🙂

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • malleswarareddy_m (5/20/2010)


    Hi,

    after for xml i executed but it opened on SSMS.But i saved it in the form XML.With IE i am unable to open.With for xml it shows in different.Please explain in detail abot this characters.but i understand that this char will return the value of the character.suppose char(65) will return A.but and also 32 is space i think.what are the charcters below 32.

    The characters below 32 are control characters. Once upon a time they were used to control devices like terminals or printers. Today only some are used regularly (tab, new line, line feed, esc...), others are used for special purposes.

    Special position is the very first character char(0): it's typically used as a string terminator in C family languages and many other environments. Always take great care using this special one char.

    There is at least one other control character: it's backspace (char (127)).

    WITH XML clause is used to turn standard query output in form of XML. It has several forms - see books online.



    See, understand, learn, try, use efficient
    © Dr.Plch

  • da-zero (5/20/2010)


    Well, it could have been a trick question 😉 🙂

    Yes, it was a trick question 😀

    Nitpickers concentrate on +=, others will find XML category 😛



    See, understand, learn, try, use efficient
    © Dr.Plch

  • Parsers are allowed to cover other characters, that's case of IE and allows this result to be displayed.

    I knew about illegal XML characters, but I felt there was a trick about Internet Explorer, so I cheated 🙂

    Other web browsers (Mozilla Firefox, Opera, and Google Chrome) show an error message about incorrect xml characters when trying to open that XML file. Tricky question about a specific application (IE)...

  • I guessed right, but the answer is wrong!

    I ran the script and got an error

    Error Character '', hexadecimal value 0x0 is illegal in XML documents.

    ie the first option, which is not the correct answer.

    As well as this error, I also got an XML segment, which I surrounded by a root element. Displaying this in IE gives an error

    'an invalid character was found in text context'.

    but displays the XML anyway.

    So the actual answer seems to be a selection of the options.

    (1) the error is given. Also (3) the XML is invalid in any environment (just because some environment might display it doesn't make it valid). But also (4) IE makes an attempt to display it (though gives an error).

  • da-zero (5/20/2010)


    honza.mf (5/19/2010)


    Maddy...! (5/19/2010)


    hello frnds....

    wht ever it may be in order to run completely a block of t-sql code it should be syntax error free

    i think there is no += operator in database so the code itself is wrong and u cant even think of it running how can you expect us to post answer for it.......

    This code is valid!

    += operator is legal in the current version of SQL Server.

    I expect people to answer questions without running code. I know, I'm old enough to be so naive.

    You should specify which environment is used in the question. As a SQL 2005 user, I saw that there would be an error. You even don't have to run the code to see that.

    I cannot guess which environment you had in mind.

    SQL Server 2008 has been around long enough that question makers can assume you'd recognise the syntax. If there had been an anwer option that matches what would happen on SQL 2005 ("illegal operator +=" or so), I'd agree with you about the trick question and the need to specify environment. But with the options given, your first impression might have been "syntax error", but then you should have reconsidered after missing that annswer option.

    As others say, this is just nitpicking; the question was clearly about XML.

    @honza.mf: Great question! I never work with XML myself so this was a good learning opportunity.

    The only thing I like less about the question was that it also required knowledge of IE to assess if the correct options was indeed correct. Had you formulated it as "XML segment, with the integrated parser marking most values illegal, but some browsers may be able to open this segment when surrounded by root element", it would have been completely perfect.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • vk-kirov (5/20/2010)


    Parsers are allowed to cover other characters, that's case of IE and allows this result to be displayed.

    I knew about illegal XML characters, but I felt there was a trick about Internet Explorer, so I cheated 🙂

    Other web browsers (Mozilla Firefox, Opera, and Google Chrome) show an error message about incorrect xml characters when trying to open that XML file. Tricky question about a specific application (IE)...

    Specific application (IE) is so specific I felt free to use it.

    IE (or it's core) is used so many ways in applications, it's knowledge is fundamental.

    It's the one browser you find near any SQL Server.

    I don't use IE if I don't have to.

    But I use some applications that use it's core.



    See, understand, learn, try, use efficient
    © Dr.Plch

  • Hugo Kornelis (5/20/2010)


    @honza.mf: Great question! I never work with XML myself so this was a good learning opportunity.

    The only thing I like less about the question was that it also required knowledge of IE to assess if the correct options was indeed correct. Had you formulated it as "XML segment, with the integrated parser marking most values illegal, but some browsers may be able to open this segment when surrounded by root element", it would have been completely perfect.

    Nearly same as in previous post to vk-kirov.

    If I used "some browsers", there could be a lot of posts "I don't care about other browsers, I use MyOwnSuperOne 5.8" 😉



    See, understand, learn, try, use efficient
    © Dr.Plch

Viewing 15 posts - 1 through 15 (of 47 total)

You must be logged in to reply to this topic. Login to reply