Control chars in XML

  • Toreador (5/20/2010)


    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.

    Courious.

    I'm using ± standard settings of SSMS and of IE too. I hadn't any error message running the query.

    You had to have something different.



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

  • honza.mf (5/20/2010)


    I'm using ± standard settings of SSMS and of IE too. I hadn't any error message running the query.

    You had to have something different.

    Actually on trying it again my memory seems to have edited bits out! I don't get that error immediately, I get it when I view the XML segment and hover over the error highlighting.

  • honza.mf (5/20/2010)


    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" 😉

    Knowledge of the standard is sufficient to answer the question *** I suggested it - as you say in the explanation, "parsers are allowed to cover other characters". Which ones do and don't use that option is irrelevant, a browser may be able to open the XML fragment.

    Your version requires not only knowledge of the w3c standard, but also of the implementation choices IE makes; I am not an IE expert (not even an IE user 99% of the time), so I had no choice but to cheat and test how IE handles these characters in XML.


    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/

  • Hugo Kornelis (5/20/2010)


    honza.mf (5/20/2010)


    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" 😉

    Knowledge of the standard is sufficient to answer the question *** I suggested it - as you say in the explanation, "parsers are allowed to cover other characters". Which ones do and don't use that option is irrelevant, a browser may be able to open the XML fragment.

    Your version requires not only knowledge of the w3c standard, but also of the implementation choices IE makes; I am not an IE expert (not even an IE user 99% of the time), so I had no choice but to cheat and test how IE handles these characters in XML.

    You are right. IE is to concrete.



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

  • honza.mf (5/20/2010)


    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.

    Thanks for reply.I know that there are different types out put for xml.

    Includes For Xml 1)path 2)auto 3)raw 4)explicit.

    But when i saved this output and opened with IE it shows some error.Even though it will open in ssms.I am using IE which is Old version 6.0.Is this error is due to IE.please explain in brief.I will open xml without error if we put like this

    select * from #t for xml AUTO,ROOT

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

  • Am I the only one who gets an error trying to display it in IE? Version 8.0.6001.18702

  • malleswarareddy_m (5/20/2010)


    Thanks for reply.I know that there are different types out put for xml.

    Includes For Xml 1)path 2)auto 3)raw 4)explicit.

    But when i saved this output and opened with IE it shows some error.Even though it will open in ssms.I am using IE which is Old version 6.0.Is this error is due to IE.please explain in brief.

    To open the file in some browser, you have to enclose the generated segment in root element. Some browsers must have XML declaration, some not.

    Use:<?xml version="1.0" encoding="utf-8"?>

    <data>

    Returned segment here

    </data>

    Be careful with th encoding parameter: it MUST fit the encoding of the file saved.



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

  • Hi,

    even me too did same !!!

    :-):-):-):-):-)

  • XML is not one of my better skills. I had to do a bit of research, and some thinking on this one. Thanks.

  • like others i found the same error in

    set @i += 1 this line of code.

    after doing like this

    set @i= @i + 1 it will work

    and generate xml file with some garbage value .

  • The point of q QotD is to have some takeaway. I don't see one here. Maybe I'm confused (quite likely), but, the XML comes up with errors and can not be displayed in IE 8 without errors.

    Not only that, but, who would create code like this anyway with all those errors in XML?

    I guess I'm just feeling ornery today... sorry. :unsure:

  • Nope. You're not alone there. I get errors, too.

  • I got it wrong but I learned a little more about XML, so not entirely a bad thing...

  • honza.mf (5/20/2010)


    malleswarareddy_m (5/20/2010)


    To open the file in some browser, you have to enclose the generated segment in root element. Some browsers must have XML declaration, some not.

    [/code]

    Hi Dr

    Great question but you got the answer wrong. There were two answers that were correct, but you are not able to see past your choice.

    1. The xml is invalid in all environs. If you leave it as it is and add nothing else that is the truth and a correct answer.

    2. However, if you are able to add something to the output then the second answer is correct it can work in IE.

    An example of how you have clouded the logic here is this:

    Which answer is correct?

    1. 1 + 1 = 2

    2. 1 + 1 = 3

    If you said 1 you are wrong. Both 1 and two are correct. You see if you put the output of #2 in IE and enclose the output in this ( answer - 1) both answers will be right.

    To be valid and logical you need to limit the correct response to the only right response without adding conditions or other items the responder does not know.

    If you do you it is like playing a card game where you makeup the rules while the game is being played, and the rules can change from hand to hand. That way you are always right and always win, but it is not fair to the other players.

    Not all gray hairs are Dinosaurs!

  • Damn, should have known. If IE can do something then that makes it valid. Oh, yeah, and should have known that I could add XML code in order for that to happen.

Viewing 15 posts - 16 through 30 (of 47 total)

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