Unwanted Escape Codes In String...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Litvack

    Unwanted Escape Codes In String...

    Hello,

    I have built an XMLDocument object instance and I get the following string
    when I examine the InnerXml property:

    <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
    QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
    AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
    AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
    AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
    AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>

    Notice that the double quotes are all escaped--that is they appear as

    \"

    versus

    "

    I would like to "transform" or "convert" this string into a string in which
    the escape characters are "converted" . This would generate a string that
    would appear like this:

    <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1 QID="55111"><Ta g2
    AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
    AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
    AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
    AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
    AID="5511505"></Tag2></Tag1></UserData></ROOT>

    I do not want to use a search/replace algorithm because I cannot be entirely
    sure that there will not be escape sequences other than \" in the string. I
    am actually seeking a solution that would "transform" the \" to " (as I
    require) but also one that would convert \n to ASCII 10 and \r to ASCII 13.
    In other words, I would like to convert the escape-encoded string to a
    standard ASCII string.

    Moreover, why does the XMLDocument's InnerXml return an escape-encoded
    string instead of a "straight" (unencoded) string? Is there a way to get the
    InnerXml to return the "straight" string? I plan to pass the XML string as
    an argument to a Sql stored procedure; therefore, the encoded string does
    not work--I must use the unencoded version. Certainly others have
    encountered this problem--I just could not find a single solution and I
    spend hours searching MSDN and Google! For example, I read some other
    threads that suggest using ActiveXMessageF ormatter, but not one of them
    actually explained how to do it--and pseudocode can only be so useful...

    Thank you in advance for any assistance. I will confirm whether any
    suggestions work.

    Regards,
    Steve






  • dd

    #2
    Re: Unwanted Escape Codes In String...

    It is the C# escape character, i.e. "\", as well as C and C++.
    You do not have to replace it with anythng. Just leave it.
    Just pass it to your stored procedure as is, it will work OK.

    "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
    news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...[color=blue]
    > Hello,
    >
    > I have built an XMLDocument object instance and I get the following string
    > when I examine the InnerXml property:
    >
    > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
    > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1[/color]
    QID=\"55112\">< Tag2[color=blue]
    > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
    > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
    > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
    > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
    >
    > Notice that the double quotes are all escaped--that is they appear as
    >
    > \"
    >
    > versus
    >
    > "
    >
    > I would like to "transform" or "convert" this string into a string in[/color]
    which[color=blue]
    > the escape characters are "converted" . This would generate a string that
    > would appear like this:
    >
    > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1 QID="55111"><Ta g2
    > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
    > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
    > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
    > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
    > AID="5511505"></Tag2></Tag1></UserData></ROOT>
    >
    > I do not want to use a search/replace algorithm because I cannot be[/color]
    entirely[color=blue]
    > sure that there will not be escape sequences other than \" in the string.[/color]
    I[color=blue]
    > am actually seeking a solution that would "transform" the \" to " (as I
    > require) but also one that would convert \n to ASCII 10 and \r to ASCII[/color]
    13.[color=blue]
    > In other words, I would like to convert the escape-encoded string to a
    > standard ASCII string.
    >
    > Moreover, why does the XMLDocument's InnerXml return an escape-encoded
    > string instead of a "straight" (unencoded) string? Is there a way to get[/color]
    the[color=blue]
    > InnerXml to return the "straight" string? I plan to pass the XML string as
    > an argument to a Sql stored procedure; therefore, the encoded string does
    > not work--I must use the unencoded version. Certainly others have
    > encountered this problem--I just could not find a single solution and I
    > spend hours searching MSDN and Google! For example, I read some other
    > threads that suggest using ActiveXMessageF ormatter, but not one of them
    > actually explained how to do it--and pseudocode can only be so useful...
    >
    > Thank you in advance for any assistance. I will confirm whether any
    > suggestions work.
    >
    > Regards,
    > Steve
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • dd

      #3
      Re: Unwanted Escape Codes In String...

      It is the C# escape character, i.e. "\", as well as C and C++.
      You do not have to replace it with anythng. Just leave it.
      Just pass it to your stored procedure as is, it will work OK.

      "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
      news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...[color=blue]
      > Hello,
      >
      > I have built an XMLDocument object instance and I get the following string
      > when I examine the InnerXml property:
      >
      > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
      > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1[/color]
      QID=\"55112\">< Tag2[color=blue]
      > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
      > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
      > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
      > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
      >
      > Notice that the double quotes are all escaped--that is they appear as
      >
      > \"
      >
      > versus
      >
      > "
      >
      > I would like to "transform" or "convert" this string into a string in[/color]
      which[color=blue]
      > the escape characters are "converted" . This would generate a string that
      > would appear like this:
      >
      > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1 QID="55111"><Ta g2
      > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
      > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
      > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
      > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
      > AID="5511505"></Tag2></Tag1></UserData></ROOT>
      >
      > I do not want to use a search/replace algorithm because I cannot be[/color]
      entirely[color=blue]
      > sure that there will not be escape sequences other than \" in the string.[/color]
      I[color=blue]
      > am actually seeking a solution that would "transform" the \" to " (as I
      > require) but also one that would convert \n to ASCII 10 and \r to ASCII[/color]
      13.[color=blue]
      > In other words, I would like to convert the escape-encoded string to a
      > standard ASCII string.
      >
      > Moreover, why does the XMLDocument's InnerXml return an escape-encoded
      > string instead of a "straight" (unencoded) string? Is there a way to get[/color]
      the[color=blue]
      > InnerXml to return the "straight" string? I plan to pass the XML string as
      > an argument to a Sql stored procedure; therefore, the encoded string does
      > not work--I must use the unencoded version. Certainly others have
      > encountered this problem--I just could not find a single solution and I
      > spend hours searching MSDN and Google! For example, I read some other
      > threads that suggest using ActiveXMessageF ormatter, but not one of them
      > actually explained how to do it--and pseudocode can only be so useful...
      >
      > Thank you in advance for any assistance. I will confirm whether any
      > suggestions work.
      >
      > Regards,
      > Steve
      >
      >
      >
      >
      >
      >[/color]


      Comment

      • dd

        #4
        Re: Unwanted Escape Codes In String...

        Can you post your SP code as well as the code that creates SP paramaters?

        "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
        news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=blue]
        > No--it does not work. That is why I posted the message.
        >
        > SQL Server reports:
        >
        > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
        Line[color=blue]
        > 27
        >
        > XML parsing error: A string literal was expected, but no opening quote
        > character was found.
        >
        >
        > If anyone has any ideas on how to generate the "pure" ASCII XML text I
        > requested, please let me know.
        >
        > Thanks,
        > -- Steve
        >
        > "dd" <someone@somewh ere.com> wrote in message
        > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=green]
        > > It is the C# escape character, i.e. "\", as well as C and C++.
        > > You do not have to replace it with anythng. Just leave it.
        > > Just pass it to your stored procedure as is, it will work OK.
        > >
        > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
        > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...[color=darkred]
        > > > Hello,
        > > >
        > > > I have built an XMLDocument object instance and I get the following[/color][/color]
        > string[color=green][color=darkred]
        > > > when I examine the InnerXml property:
        > > >
        > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
        > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1[/color]
        > > QID=\"55112\">< Tag2[color=darkred]
        > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
        > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
        > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
        > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
        > > >
        > > > Notice that the double quotes are all escaped--that is they appear as
        > > >
        > > > \"
        > > >
        > > > versus
        > > >
        > > > "
        > > >
        > > > I would like to "transform" or "convert" this string into a string in[/color]
        > > which[color=darkred]
        > > > the escape characters are "converted" . This would generate a string[/color][/color][/color]
        that[color=blue][color=green][color=darkred]
        > > > would appear like this:
        > > >
        > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color][/color]
        > QID="55111"><Ta g2[color=green][color=darkred]
        > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
        > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
        > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
        > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
        > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
        > > >
        > > > I do not want to use a search/replace algorithm because I cannot be[/color]
        > > entirely[color=darkred]
        > > > sure that there will not be escape sequences other than \" in the[/color][/color]
        > string.[color=green]
        > > I[color=darkred]
        > > > am actually seeking a solution that would "transform" the \" to " (as[/color][/color][/color]
        I[color=blue][color=green][color=darkred]
        > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color][/color]
        ASCII[color=blue][color=green]
        > > 13.[color=darkred]
        > > > In other words, I would like to convert the escape-encoded string to a
        > > > standard ASCII string.
        > > >
        > > > Moreover, why does the XMLDocument's InnerXml return an escape-encoded
        > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color][/color]
        get[color=blue][color=green]
        > > the[color=darkred]
        > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color][/color]
        string[color=blue]
        > as[color=green][color=darkred]
        > > > an argument to a Sql stored procedure; therefore, the encoded string[/color][/color]
        > does[color=green][color=darkred]
        > > > not work--I must use the unencoded version. Certainly others have
        > > > encountered this problem--I just could not find a single solution and[/color][/color][/color]
        I[color=blue][color=green][color=darkred]
        > > > spend hours searching MSDN and Google! For example, I read some other
        > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color][/color]
        them[color=blue][color=green][color=darkred]
        > > > actually explained how to do it--and pseudocode can only be so[/color][/color][/color]
        useful...[color=blue][color=green][color=darkred]
        > > >
        > > > Thank you in advance for any assistance. I will confirm whether any
        > > > suggestions work.
        > > >
        > > > Regards,
        > > > Steve
        > > >
        > > >
        > > >
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • dd

          #5
          Re: Unwanted Escape Codes In String...

          Can you post your SP code as well as the code that creates SP paramaters?

          "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
          news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=blue]
          > No--it does not work. That is why I posted the message.
          >
          > SQL Server reports:
          >
          > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
          Line[color=blue]
          > 27
          >
          > XML parsing error: A string literal was expected, but no opening quote
          > character was found.
          >
          >
          > If anyone has any ideas on how to generate the "pure" ASCII XML text I
          > requested, please let me know.
          >
          > Thanks,
          > -- Steve
          >
          > "dd" <someone@somewh ere.com> wrote in message
          > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=green]
          > > It is the C# escape character, i.e. "\", as well as C and C++.
          > > You do not have to replace it with anythng. Just leave it.
          > > Just pass it to your stored procedure as is, it will work OK.
          > >
          > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
          > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...[color=darkred]
          > > > Hello,
          > > >
          > > > I have built an XMLDocument object instance and I get the following[/color][/color]
          > string[color=green][color=darkred]
          > > > when I examine the InnerXml property:
          > > >
          > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
          > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1[/color]
          > > QID=\"55112\">< Tag2[color=darkred]
          > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
          > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
          > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
          > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
          > > >
          > > > Notice that the double quotes are all escaped--that is they appear as
          > > >
          > > > \"
          > > >
          > > > versus
          > > >
          > > > "
          > > >
          > > > I would like to "transform" or "convert" this string into a string in[/color]
          > > which[color=darkred]
          > > > the escape characters are "converted" . This would generate a string[/color][/color][/color]
          that[color=blue][color=green][color=darkred]
          > > > would appear like this:
          > > >
          > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color][/color]
          > QID="55111"><Ta g2[color=green][color=darkred]
          > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
          > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
          > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
          > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
          > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
          > > >
          > > > I do not want to use a search/replace algorithm because I cannot be[/color]
          > > entirely[color=darkred]
          > > > sure that there will not be escape sequences other than \" in the[/color][/color]
          > string.[color=green]
          > > I[color=darkred]
          > > > am actually seeking a solution that would "transform" the \" to " (as[/color][/color][/color]
          I[color=blue][color=green][color=darkred]
          > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color][/color]
          ASCII[color=blue][color=green]
          > > 13.[color=darkred]
          > > > In other words, I would like to convert the escape-encoded string to a
          > > > standard ASCII string.
          > > >
          > > > Moreover, why does the XMLDocument's InnerXml return an escape-encoded
          > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color][/color]
          get[color=blue][color=green]
          > > the[color=darkred]
          > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color][/color]
          string[color=blue]
          > as[color=green][color=darkred]
          > > > an argument to a Sql stored procedure; therefore, the encoded string[/color][/color]
          > does[color=green][color=darkred]
          > > > not work--I must use the unencoded version. Certainly others have
          > > > encountered this problem--I just could not find a single solution and[/color][/color][/color]
          I[color=blue][color=green][color=darkred]
          > > > spend hours searching MSDN and Google! For example, I read some other
          > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color][/color]
          them[color=blue][color=green][color=darkred]
          > > > actually explained how to do it--and pseudocode can only be so[/color][/color][/color]
          useful...[color=blue][color=green][color=darkred]
          > > >
          > > > Thank you in advance for any assistance. I will confirm whether any
          > > > suggestions work.
          > > >
          > > > Regards,
          > > > Steve
          > > >
          > > >
          > > >
          > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • dd

            #6
            Re: Unwanted Escape Codes In String...

            Your problem is not the escape character, and it has nothing to do with
            "pure" ASCII XML text. If your stored procedure has no errors and you are
            passing your parameter properly, it should work without any problems. Here
            is the code that I tried and it worked.

            private SqlParameter CreateParameter (string sName, SqlDbType lType, int
            iSize, ParameterDirect ion lDir,

            bool bNullable, string sValue)

            {

            SqlParameter oParameter = new SqlParameter(sN ame, lType);

            oParameter.Size = iSize;

            oParameter.Dire ction = lDir;

            oParameter.IsNu llable = bNullable;

            oParameter.Valu e = sValue;

            return oParameter;

            }

            private void button1_Click(o bject sender, System.EventArg s e)

            {

            string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
            UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
            AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
            AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
            AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
            AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
            AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";

            SqlConnection oConn = new SqlConnection() ;

            SqlCommand oCmd = new SqlCommand();

            oConn.Connectio nString = "your connection string";

            try{oConn.Open( );}

            catch(Exception ex){string sException = ex.Message;};

            oCmd.Connection = oConn;

            oCmd.CommandTyp e = CommandType.Sto redProcedure;

            oCmd.CommandTex t = "sp_Test";

            oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900 ,
            ParameterDirect ion.Input,

            false, sString));

            try

            {

            oCmd.ExecuteNon Query();

            }

            catch(System.Ex ception ex){string sException = ex.Message;}

            oConn.Close();

            oCmd.Dispose(); oConn.Dispose() ;

            }



            Here is the stored provedure:

            CREATE PROCEDURE sp_Test

            @StringIn varchar(900)
            AS
            DECLARE @hdoc int
            --Create an internal representation of the XML document.
            EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
            EXEC sp_xml_removedo cument @hDoc

            GO

            "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
            news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=blue]
            > No--it does not work. That is why I posted the message.
            >
            > SQL Server reports:
            >
            > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
            Line[color=blue]
            > 27
            >
            > XML parsing error: A string literal was expected, but no opening quote
            > character was found.
            >
            >
            > If anyone has any ideas on how to generate the "pure" ASCII XML text I
            > requested, please let me know.
            >
            > Thanks,
            > -- Steve
            >
            > "dd" <someone@somewh ere.com> wrote in message
            > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=green]
            > > It is the C# escape character, i.e. "\", as well as C and C++.
            > > You do not have to replace it with anythng. Just leave it.
            > > Just pass it to your stored procedure as is, it will work OK.
            > >
            > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
            > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...[color=darkred]
            > > > Hello,
            > > >
            > > > I have built an XMLDocument object instance and I get the following[/color][/color]
            > string[color=green][color=darkred]
            > > > when I examine the InnerXml property:
            > > >
            > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
            > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1[/color]
            > > QID=\"55112\">< Tag2[color=darkred]
            > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
            > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
            > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
            > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
            > > >
            > > > Notice that the double quotes are all escaped--that is they appear as
            > > >
            > > > \"
            > > >
            > > > versus
            > > >
            > > > "
            > > >
            > > > I would like to "transform" or "convert" this string into a string in[/color]
            > > which[color=darkred]
            > > > the escape characters are "converted" . This would generate a string[/color][/color][/color]
            that[color=blue][color=green][color=darkred]
            > > > would appear like this:
            > > >
            > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color][/color]
            > QID="55111"><Ta g2[color=green][color=darkred]
            > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
            > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
            > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
            > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
            > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
            > > >
            > > > I do not want to use a search/replace algorithm because I cannot be[/color]
            > > entirely[color=darkred]
            > > > sure that there will not be escape sequences other than \" in the[/color][/color]
            > string.[color=green]
            > > I[color=darkred]
            > > > am actually seeking a solution that would "transform" the \" to " (as[/color][/color][/color]
            I[color=blue][color=green][color=darkred]
            > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color][/color]
            ASCII[color=blue][color=green]
            > > 13.[color=darkred]
            > > > In other words, I would like to convert the escape-encoded string to a
            > > > standard ASCII string.
            > > >
            > > > Moreover, why does the XMLDocument's InnerXml return an escape-encoded
            > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color][/color]
            get[color=blue][color=green]
            > > the[color=darkred]
            > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color][/color]
            string[color=blue]
            > as[color=green][color=darkred]
            > > > an argument to a Sql stored procedure; therefore, the encoded string[/color][/color]
            > does[color=green][color=darkred]
            > > > not work--I must use the unencoded version. Certainly others have
            > > > encountered this problem--I just could not find a single solution and[/color][/color][/color]
            I[color=blue][color=green][color=darkred]
            > > > spend hours searching MSDN and Google! For example, I read some other
            > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color][/color]
            them[color=blue][color=green][color=darkred]
            > > > actually explained how to do it--and pseudocode can only be so[/color][/color][/color]
            useful...[color=blue][color=green][color=darkred]
            > > >
            > > > Thank you in advance for any assistance. I will confirm whether any
            > > > suggestions work.
            > > >
            > > > Regards,
            > > > Steve
            > > >
            > > >
            > > >
            > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • dd

              #7
              Re: Unwanted Escape Codes In String...

              Your problem is not the escape character, and it has nothing to do with
              "pure" ASCII XML text. If your stored procedure has no errors and you are
              passing your parameter properly, it should work without any problems. Here
              is the code that I tried and it worked.

              private SqlParameter CreateParameter (string sName, SqlDbType lType, int
              iSize, ParameterDirect ion lDir,

              bool bNullable, string sValue)

              {

              SqlParameter oParameter = new SqlParameter(sN ame, lType);

              oParameter.Size = iSize;

              oParameter.Dire ction = lDir;

              oParameter.IsNu llable = bNullable;

              oParameter.Valu e = sValue;

              return oParameter;

              }

              private void button1_Click(o bject sender, System.EventArg s e)

              {

              string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
              UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
              AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
              AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
              AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
              AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
              AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";

              SqlConnection oConn = new SqlConnection() ;

              SqlCommand oCmd = new SqlCommand();

              oConn.Connectio nString = "your connection string";

              try{oConn.Open( );}

              catch(Exception ex){string sException = ex.Message;};

              oCmd.Connection = oConn;

              oCmd.CommandTyp e = CommandType.Sto redProcedure;

              oCmd.CommandTex t = "sp_Test";

              oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900 ,
              ParameterDirect ion.Input,

              false, sString));

              try

              {

              oCmd.ExecuteNon Query();

              }

              catch(System.Ex ception ex){string sException = ex.Message;}

              oConn.Close();

              oCmd.Dispose(); oConn.Dispose() ;

              }



              Here is the stored provedure:

              CREATE PROCEDURE sp_Test

              @StringIn varchar(900)
              AS
              DECLARE @hdoc int
              --Create an internal representation of the XML document.
              EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
              EXEC sp_xml_removedo cument @hDoc

              GO

              "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
              news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=blue]
              > No--it does not work. That is why I posted the message.
              >
              > SQL Server reports:
              >
              > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
              Line[color=blue]
              > 27
              >
              > XML parsing error: A string literal was expected, but no opening quote
              > character was found.
              >
              >
              > If anyone has any ideas on how to generate the "pure" ASCII XML text I
              > requested, please let me know.
              >
              > Thanks,
              > -- Steve
              >
              > "dd" <someone@somewh ere.com> wrote in message
              > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=green]
              > > It is the C# escape character, i.e. "\", as well as C and C++.
              > > You do not have to replace it with anythng. Just leave it.
              > > Just pass it to your stored procedure as is, it will work OK.
              > >
              > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
              > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...[color=darkred]
              > > > Hello,
              > > >
              > > > I have built an XMLDocument object instance and I get the following[/color][/color]
              > string[color=green][color=darkred]
              > > > when I examine the InnerXml property:
              > > >
              > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
              > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1[/color]
              > > QID=\"55112\">< Tag2[color=darkred]
              > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
              > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
              > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
              > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
              > > >
              > > > Notice that the double quotes are all escaped--that is they appear as
              > > >
              > > > \"
              > > >
              > > > versus
              > > >
              > > > "
              > > >
              > > > I would like to "transform" or "convert" this string into a string in[/color]
              > > which[color=darkred]
              > > > the escape characters are "converted" . This would generate a string[/color][/color][/color]
              that[color=blue][color=green][color=darkred]
              > > > would appear like this:
              > > >
              > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color][/color]
              > QID="55111"><Ta g2[color=green][color=darkred]
              > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
              > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
              > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
              > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
              > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
              > > >
              > > > I do not want to use a search/replace algorithm because I cannot be[/color]
              > > entirely[color=darkred]
              > > > sure that there will not be escape sequences other than \" in the[/color][/color]
              > string.[color=green]
              > > I[color=darkred]
              > > > am actually seeking a solution that would "transform" the \" to " (as[/color][/color][/color]
              I[color=blue][color=green][color=darkred]
              > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color][/color]
              ASCII[color=blue][color=green]
              > > 13.[color=darkred]
              > > > In other words, I would like to convert the escape-encoded string to a
              > > > standard ASCII string.
              > > >
              > > > Moreover, why does the XMLDocument's InnerXml return an escape-encoded
              > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color][/color]
              get[color=blue][color=green]
              > > the[color=darkred]
              > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color][/color]
              string[color=blue]
              > as[color=green][color=darkred]
              > > > an argument to a Sql stored procedure; therefore, the encoded string[/color][/color]
              > does[color=green][color=darkred]
              > > > not work--I must use the unencoded version. Certainly others have
              > > > encountered this problem--I just could not find a single solution and[/color][/color][/color]
              I[color=blue][color=green][color=darkred]
              > > > spend hours searching MSDN and Google! For example, I read some other
              > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color][/color]
              them[color=blue][color=green][color=darkred]
              > > > actually explained how to do it--and pseudocode can only be so[/color][/color][/color]
              useful...[color=blue][color=green][color=darkred]
              > > >
              > > > Thank you in advance for any assistance. I will confirm whether any
              > > > suggestions work.
              > > >
              > > > Regards,
              > > > Steve
              > > >
              > > >
              > > >
              > > >
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Steve Litvack

                #8
                Re: Unwanted Escape Codes In String...

                OK... This obviously is one of those problems where the stored proc works
                with "well-formed" (what I call "pure") XML yet does not work with XML
                containing escape sequences. This made it appear to be a problem with the
                XML I'm using. However, thanks to your efforts you have convinced me that
                the problem can also be fixed by reviewing the stored proc and leaving my
                XML as-is. Thus, this problem seems to have two solutions: change the XML or
                change the sproc.

                I will do a little more research on this issue, study what you have kindly
                written (and thank you for taking the time you clearly took), and I will
                reply with either more information or with the solution(s) I have found.

                Regards,
                -- Steve

                "dd" <someone@somewh ere.com> wrote in message
                news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=blue]
                > Your problem is not the escape character, and it has nothing to do with
                > "pure" ASCII XML text. If your stored procedure has no errors and you are
                > passing your parameter properly, it should work without any problems. Here
                > is the code that I tried and it worked.
                >
                > private SqlParameter CreateParameter (string sName, SqlDbType lType, int
                > iSize, ParameterDirect ion lDir,
                >
                > bool bNullable, string sValue)
                >
                > {
                >
                > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                >
                > oParameter.Size = iSize;
                >
                > oParameter.Dire ction = lDir;
                >
                > oParameter.IsNu llable = bNullable;
                >
                > oParameter.Valu e = sValue;
                >
                > return oParameter;
                >
                > }
                >
                > private void button1_Click(o bject sender, System.EventArg s e)
                >
                > {
                >
                > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                >
                > SqlConnection oConn = new SqlConnection() ;
                >
                > SqlCommand oCmd = new SqlCommand();
                >
                > oConn.Connectio nString = "your connection string";
                >
                > try{oConn.Open( );}
                >
                > catch(Exception ex){string sException = ex.Message;};
                >
                > oCmd.Connection = oConn;
                >
                > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                >
                > oCmd.CommandTex t = "sp_Test";
                >
                > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900 ,
                > ParameterDirect ion.Input,
                >
                > false, sString));
                >
                > try
                >
                > {
                >
                > oCmd.ExecuteNon Query();
                >
                > }
                >
                > catch(System.Ex ception ex){string sException = ex.Message;}
                >
                > oConn.Close();
                >
                > oCmd.Dispose(); oConn.Dispose() ;
                >
                > }
                >
                >
                >
                > Here is the stored provedure:
                >
                > CREATE PROCEDURE sp_Test
                >
                > @StringIn varchar(900)
                > AS
                > DECLARE @hdoc int
                > --Create an internal representation of the XML document.
                > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                > EXEC sp_xml_removedo cument @hDoc
                >
                > GO
                >
                > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=green]
                > > No--it does not work. That is why I posted the message.
                > >
                > > SQL Server reports:
                > >
                > > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
                > Line[color=green]
                > > 27
                > >
                > > XML parsing error: A string literal was expected, but no opening quote
                > > character was found.
                > >
                > >
                > > If anyone has any ideas on how to generate the "pure" ASCII XML text I
                > > requested, please let me know.
                > >
                > > Thanks,
                > > -- Steve
                > >
                > > "dd" <someone@somewh ere.com> wrote in message
                > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=darkred]
                > > > It is the C# escape character, i.e. "\", as well as C and C++.
                > > > You do not have to replace it with anythng. Just leave it.
                > > > Just pass it to your stored procedure as is, it will work OK.
                > > >
                > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                > > > > Hello,
                > > > >
                > > > > I have built an XMLDocument object instance and I get the following[/color]
                > > string[color=darkred]
                > > > > when I examine the InnerXml property:
                > > > >
                > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                > > > QID=\"55112\">< Tag2
                > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                > > > >
                > > > > Notice that the double quotes are all escaped--that is they appear[/color][/color][/color]
                as[color=blue][color=green][color=darkred]
                > > > >
                > > > > \"
                > > > >
                > > > > versus
                > > > >
                > > > > "
                > > > >
                > > > > I would like to "transform" or "convert" this string into a string[/color][/color][/color]
                in[color=blue][color=green][color=darkred]
                > > > which
                > > > > the escape characters are "converted" . This would generate a string[/color][/color]
                > that[color=green][color=darkred]
                > > > > would appear like this:
                > > > >
                > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color]
                > > QID="55111"><Ta g2[color=darkred]
                > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                > > > >
                > > > > I do not want to use a search/replace algorithm because I cannot be
                > > > entirely
                > > > > sure that there will not be escape sequences other than \" in the[/color]
                > > string.[color=darkred]
                > > > I
                > > > > am actually seeking a solution that would "transform" the \" to "[/color][/color][/color]
                (as[color=blue]
                > I[color=green][color=darkred]
                > > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color]
                > ASCII[color=green][color=darkred]
                > > > 13.
                > > > > In other words, I would like to convert the escape-encoded string to[/color][/color][/color]
                a[color=blue][color=green][color=darkred]
                > > > > standard ASCII string.
                > > > >
                > > > > Moreover, why does the XMLDocument's InnerXml return an[/color][/color][/color]
                escape-encoded[color=blue][color=green][color=darkred]
                > > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color]
                > get[color=green][color=darkred]
                > > > the
                > > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color]
                > string[color=green]
                > > as[color=darkred]
                > > > > an argument to a Sql stored procedure; therefore, the encoded string[/color]
                > > does[color=darkred]
                > > > > not work--I must use the unencoded version. Certainly others have
                > > > > encountered this problem--I just could not find a single solution[/color][/color][/color]
                and[color=blue]
                > I[color=green][color=darkred]
                > > > > spend hours searching MSDN and Google! For example, I read some[/color][/color][/color]
                other[color=blue][color=green][color=darkred]
                > > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color]
                > them[color=green][color=darkred]
                > > > > actually explained how to do it--and pseudocode can only be so[/color][/color]
                > useful...[color=green][color=darkred]
                > > > >
                > > > > Thank you in advance for any assistance. I will confirm whether any
                > > > > suggestions work.
                > > > >
                > > > > Regards,
                > > > > Steve
                > > > >
                > > > >
                > > > >
                > > > >
                > > > >
                > > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • Steve Litvack

                  #9
                  Re: Unwanted Escape Codes In String...

                  OK... This obviously is one of those problems where the stored proc works
                  with "well-formed" (what I call "pure") XML yet does not work with XML
                  containing escape sequences. This made it appear to be a problem with the
                  XML I'm using. However, thanks to your efforts you have convinced me that
                  the problem can also be fixed by reviewing the stored proc and leaving my
                  XML as-is. Thus, this problem seems to have two solutions: change the XML or
                  change the sproc.

                  I will do a little more research on this issue, study what you have kindly
                  written (and thank you for taking the time you clearly took), and I will
                  reply with either more information or with the solution(s) I have found.

                  Regards,
                  -- Steve

                  "dd" <someone@somewh ere.com> wrote in message
                  news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=blue]
                  > Your problem is not the escape character, and it has nothing to do with
                  > "pure" ASCII XML text. If your stored procedure has no errors and you are
                  > passing your parameter properly, it should work without any problems. Here
                  > is the code that I tried and it worked.
                  >
                  > private SqlParameter CreateParameter (string sName, SqlDbType lType, int
                  > iSize, ParameterDirect ion lDir,
                  >
                  > bool bNullable, string sValue)
                  >
                  > {
                  >
                  > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                  >
                  > oParameter.Size = iSize;
                  >
                  > oParameter.Dire ction = lDir;
                  >
                  > oParameter.IsNu llable = bNullable;
                  >
                  > oParameter.Valu e = sValue;
                  >
                  > return oParameter;
                  >
                  > }
                  >
                  > private void button1_Click(o bject sender, System.EventArg s e)
                  >
                  > {
                  >
                  > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                  > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                  > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                  > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                  > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                  > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                  > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                  >
                  > SqlConnection oConn = new SqlConnection() ;
                  >
                  > SqlCommand oCmd = new SqlCommand();
                  >
                  > oConn.Connectio nString = "your connection string";
                  >
                  > try{oConn.Open( );}
                  >
                  > catch(Exception ex){string sException = ex.Message;};
                  >
                  > oCmd.Connection = oConn;
                  >
                  > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                  >
                  > oCmd.CommandTex t = "sp_Test";
                  >
                  > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900 ,
                  > ParameterDirect ion.Input,
                  >
                  > false, sString));
                  >
                  > try
                  >
                  > {
                  >
                  > oCmd.ExecuteNon Query();
                  >
                  > }
                  >
                  > catch(System.Ex ception ex){string sException = ex.Message;}
                  >
                  > oConn.Close();
                  >
                  > oCmd.Dispose(); oConn.Dispose() ;
                  >
                  > }
                  >
                  >
                  >
                  > Here is the stored provedure:
                  >
                  > CREATE PROCEDURE sp_Test
                  >
                  > @StringIn varchar(900)
                  > AS
                  > DECLARE @hdoc int
                  > --Create an internal representation of the XML document.
                  > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                  > EXEC sp_xml_removedo cument @hDoc
                  >
                  > GO
                  >
                  > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                  > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=green]
                  > > No--it does not work. That is why I posted the message.
                  > >
                  > > SQL Server reports:
                  > >
                  > > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
                  > Line[color=green]
                  > > 27
                  > >
                  > > XML parsing error: A string literal was expected, but no opening quote
                  > > character was found.
                  > >
                  > >
                  > > If anyone has any ideas on how to generate the "pure" ASCII XML text I
                  > > requested, please let me know.
                  > >
                  > > Thanks,
                  > > -- Steve
                  > >
                  > > "dd" <someone@somewh ere.com> wrote in message
                  > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=darkred]
                  > > > It is the C# escape character, i.e. "\", as well as C and C++.
                  > > > You do not have to replace it with anythng. Just leave it.
                  > > > Just pass it to your stored procedure as is, it will work OK.
                  > > >
                  > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                  > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                  > > > > Hello,
                  > > > >
                  > > > > I have built an XMLDocument object instance and I get the following[/color]
                  > > string[color=darkred]
                  > > > > when I examine the InnerXml property:
                  > > > >
                  > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                  > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                  > > > QID=\"55112\">< Tag2
                  > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                  > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                  > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                  > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                  > > > >
                  > > > > Notice that the double quotes are all escaped--that is they appear[/color][/color][/color]
                  as[color=blue][color=green][color=darkred]
                  > > > >
                  > > > > \"
                  > > > >
                  > > > > versus
                  > > > >
                  > > > > "
                  > > > >
                  > > > > I would like to "transform" or "convert" this string into a string[/color][/color][/color]
                  in[color=blue][color=green][color=darkred]
                  > > > which
                  > > > > the escape characters are "converted" . This would generate a string[/color][/color]
                  > that[color=green][color=darkred]
                  > > > > would appear like this:
                  > > > >
                  > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color]
                  > > QID="55111"><Ta g2[color=darkred]
                  > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                  > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                  > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                  > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                  > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                  > > > >
                  > > > > I do not want to use a search/replace algorithm because I cannot be
                  > > > entirely
                  > > > > sure that there will not be escape sequences other than \" in the[/color]
                  > > string.[color=darkred]
                  > > > I
                  > > > > am actually seeking a solution that would "transform" the \" to "[/color][/color][/color]
                  (as[color=blue]
                  > I[color=green][color=darkred]
                  > > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color]
                  > ASCII[color=green][color=darkred]
                  > > > 13.
                  > > > > In other words, I would like to convert the escape-encoded string to[/color][/color][/color]
                  a[color=blue][color=green][color=darkred]
                  > > > > standard ASCII string.
                  > > > >
                  > > > > Moreover, why does the XMLDocument's InnerXml return an[/color][/color][/color]
                  escape-encoded[color=blue][color=green][color=darkred]
                  > > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color]
                  > get[color=green][color=darkred]
                  > > > the
                  > > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color]
                  > string[color=green]
                  > > as[color=darkred]
                  > > > > an argument to a Sql stored procedure; therefore, the encoded string[/color]
                  > > does[color=darkred]
                  > > > > not work--I must use the unencoded version. Certainly others have
                  > > > > encountered this problem--I just could not find a single solution[/color][/color][/color]
                  and[color=blue]
                  > I[color=green][color=darkred]
                  > > > > spend hours searching MSDN and Google! For example, I read some[/color][/color][/color]
                  other[color=blue][color=green][color=darkred]
                  > > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color]
                  > them[color=green][color=darkred]
                  > > > > actually explained how to do it--and pseudocode can only be so[/color][/color]
                  > useful...[color=green][color=darkred]
                  > > > >
                  > > > > Thank you in advance for any assistance. I will confirm whether any
                  > > > > suggestions work.
                  > > > >
                  > > > > Regards,
                  > > > > Steve
                  > > > >
                  > > > >
                  > > > >
                  > > > >
                  > > > >
                  > > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • dd

                    #10
                    Re: Unwanted Escape Codes In String...

                    Steve,
                    If you pass your string, which is a string that contains escape codes, using
                    Command Parameters it will work OK.
                    The escape characters will be taken care of by the parameter object, and the
                    string will be passed to the stored procedure as it is supposed to be, i.e.
                    no escape characters will be passed to the stored procedure. Consequently,
                    XMLDoc object inside your stored procedure will take it. Just use
                    parameters, that's all.

                    "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                    news:_y0Xa.1484 70$xg5.27620@tw ister.austin.rr .com...[color=blue]
                    > OK... This obviously is one of those problems where the stored proc works
                    > with "well-formed" (what I call "pure") XML yet does not work with XML
                    > containing escape sequences. This made it appear to be a problem with the
                    > XML I'm using. However, thanks to your efforts you have convinced me that
                    > the problem can also be fixed by reviewing the stored proc and leaving my
                    > XML as-is. Thus, this problem seems to have two solutions: change the XML[/color]
                    or[color=blue]
                    > change the sproc.
                    >
                    > I will do a little more research on this issue, study what you have kindly
                    > written (and thank you for taking the time you clearly took), and I will
                    > reply with either more information or with the solution(s) I have found.
                    >
                    > Regards,
                    > -- Steve
                    >
                    > "dd" <someone@somewh ere.com> wrote in message
                    > news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=green]
                    > > Your problem is not the escape character, and it has nothing to do with
                    > > "pure" ASCII XML text. If your stored procedure has no errors and you[/color][/color]
                    are[color=blue][color=green]
                    > > passing your parameter properly, it should work without any problems.[/color][/color]
                    Here[color=blue][color=green]
                    > > is the code that I tried and it worked.
                    > >
                    > > private SqlParameter CreateParameter (string sName, SqlDbType lType, int
                    > > iSize, ParameterDirect ion lDir,
                    > >
                    > > bool bNullable, string sValue)
                    > >
                    > > {
                    > >
                    > > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                    > >
                    > > oParameter.Size = iSize;
                    > >
                    > > oParameter.Dire ction = lDir;
                    > >
                    > > oParameter.IsNu llable = bNullable;
                    > >
                    > > oParameter.Valu e = sValue;
                    > >
                    > > return oParameter;
                    > >
                    > > }
                    > >
                    > > private void button1_Click(o bject sender, System.EventArg s e)
                    > >
                    > > {
                    > >
                    > > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                    > > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                    > > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                    > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                    > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                    > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                    > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                    > >
                    > > SqlConnection oConn = new SqlConnection() ;
                    > >
                    > > SqlCommand oCmd = new SqlCommand();
                    > >
                    > > oConn.Connectio nString = "your connection string";
                    > >
                    > > try{oConn.Open( );}
                    > >
                    > > catch(Exception ex){string sException = ex.Message;};
                    > >
                    > > oCmd.Connection = oConn;
                    > >
                    > > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                    > >
                    > > oCmd.CommandTex t = "sp_Test";
                    > >
                    > > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900[/color][/color]
                    ,[color=blue][color=green]
                    > > ParameterDirect ion.Input,
                    > >
                    > > false, sString));
                    > >
                    > > try
                    > >
                    > > {
                    > >
                    > > oCmd.ExecuteNon Query();
                    > >
                    > > }
                    > >
                    > > catch(System.Ex ception ex){string sException = ex.Message;}
                    > >
                    > > oConn.Close();
                    > >
                    > > oCmd.Dispose(); oConn.Dispose() ;
                    > >
                    > > }
                    > >
                    > >
                    > >
                    > > Here is the stored provedure:
                    > >
                    > > CREATE PROCEDURE sp_Test
                    > >
                    > > @StringIn varchar(900)
                    > > AS
                    > > DECLARE @hdoc int
                    > > --Create an internal representation of the XML document.
                    > > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                    > > EXEC sp_xml_removedo cument @hDoc
                    > >
                    > > GO
                    > >
                    > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                    > > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=darkred]
                    > > > No--it does not work. That is why I posted the message.
                    > > >
                    > > > SQL Server reports:
                    > > >
                    > > > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
                    > > Line[color=darkred]
                    > > > 27
                    > > >
                    > > > XML parsing error: A string literal was expected, but no opening quote
                    > > > character was found.
                    > > >
                    > > >
                    > > > If anyone has any ideas on how to generate the "pure" ASCII XML text I
                    > > > requested, please let me know.
                    > > >
                    > > > Thanks,
                    > > > -- Steve
                    > > >
                    > > > "dd" <someone@somewh ere.com> wrote in message
                    > > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...
                    > > > > It is the C# escape character, i.e. "\", as well as C and C++.
                    > > > > You do not have to replace it with anythng. Just leave it.
                    > > > > Just pass it to your stored procedure as is, it will work OK.
                    > > > >
                    > > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                    > > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                    > > > > > Hello,
                    > > > > >
                    > > > > > I have built an XMLDocument object instance and I get the[/color][/color][/color]
                    following[color=blue][color=green][color=darkred]
                    > > > string
                    > > > > > when I examine the InnerXml property:
                    > > > > >
                    > > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                    > > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                    > > > > QID=\"55112\">< Tag2
                    > > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                    > > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                    > > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                    > > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                    > > > > >
                    > > > > > Notice that the double quotes are all escaped--that is they appear[/color][/color]
                    > as[color=green][color=darkred]
                    > > > > >
                    > > > > > \"
                    > > > > >
                    > > > > > versus
                    > > > > >
                    > > > > > "
                    > > > > >
                    > > > > > I would like to "transform" or "convert" this string into a string[/color][/color]
                    > in[color=green][color=darkred]
                    > > > > which
                    > > > > > the escape characters are "converted" . This would generate a[/color][/color][/color]
                    string[color=blue][color=green]
                    > > that[color=darkred]
                    > > > > > would appear like this:
                    > > > > >
                    > > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1
                    > > > QID="55111"><Ta g2
                    > > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                    > > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                    > > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                    > > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                    > > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                    > > > > >
                    > > > > > I do not want to use a search/replace algorithm because I cannot[/color][/color][/color]
                    be[color=blue][color=green][color=darkred]
                    > > > > entirely
                    > > > > > sure that there will not be escape sequences other than \" in the
                    > > > string.
                    > > > > I
                    > > > > > am actually seeking a solution that would "transform" the \" to "[/color][/color]
                    > (as[color=green]
                    > > I[color=darkred]
                    > > > > > require) but also one that would convert \n to ASCII 10 and \r to[/color]
                    > > ASCII[color=darkred]
                    > > > > 13.
                    > > > > > In other words, I would like to convert the escape-encoded string[/color][/color][/color]
                    to[color=blue]
                    > a[color=green][color=darkred]
                    > > > > > standard ASCII string.
                    > > > > >
                    > > > > > Moreover, why does the XMLDocument's InnerXml return an[/color][/color]
                    > escape-encoded[color=green][color=darkred]
                    > > > > > string instead of a "straight" (unencoded) string? Is there a way[/color][/color][/color]
                    to[color=blue][color=green]
                    > > get[color=darkred]
                    > > > > the
                    > > > > > InnerXml to return the "straight" string? I plan to pass the XML[/color]
                    > > string[color=darkred]
                    > > > as
                    > > > > > an argument to a Sql stored procedure; therefore, the encoded[/color][/color][/color]
                    string[color=blue][color=green][color=darkred]
                    > > > does
                    > > > > > not work--I must use the unencoded version. Certainly others have
                    > > > > > encountered this problem--I just could not find a single solution[/color][/color]
                    > and[color=green]
                    > > I[color=darkred]
                    > > > > > spend hours searching MSDN and Google! For example, I read some[/color][/color]
                    > other[color=green][color=darkred]
                    > > > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color]
                    > > them[color=darkred]
                    > > > > > actually explained how to do it--and pseudocode can only be so[/color]
                    > > useful...[color=darkred]
                    > > > > >
                    > > > > > Thank you in advance for any assistance. I will confirm whether[/color][/color][/color]
                    any[color=blue][color=green][color=darkred]
                    > > > > > suggestions work.
                    > > > > >
                    > > > > > Regards,
                    > > > > > Steve
                    > > > > >
                    > > > > >
                    > > > > >
                    > > > > >
                    > > > > >
                    > > > > >
                    > > > >
                    > > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • dd

                      #11
                      Re: Unwanted Escape Codes In String...

                      Steve,
                      If you pass your string, which is a string that contains escape codes, using
                      Command Parameters it will work OK.
                      The escape characters will be taken care of by the parameter object, and the
                      string will be passed to the stored procedure as it is supposed to be, i.e.
                      no escape characters will be passed to the stored procedure. Consequently,
                      XMLDoc object inside your stored procedure will take it. Just use
                      parameters, that's all.

                      "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                      news:_y0Xa.1484 70$xg5.27620@tw ister.austin.rr .com...[color=blue]
                      > OK... This obviously is one of those problems where the stored proc works
                      > with "well-formed" (what I call "pure") XML yet does not work with XML
                      > containing escape sequences. This made it appear to be a problem with the
                      > XML I'm using. However, thanks to your efforts you have convinced me that
                      > the problem can also be fixed by reviewing the stored proc and leaving my
                      > XML as-is. Thus, this problem seems to have two solutions: change the XML[/color]
                      or[color=blue]
                      > change the sproc.
                      >
                      > I will do a little more research on this issue, study what you have kindly
                      > written (and thank you for taking the time you clearly took), and I will
                      > reply with either more information or with the solution(s) I have found.
                      >
                      > Regards,
                      > -- Steve
                      >
                      > "dd" <someone@somewh ere.com> wrote in message
                      > news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=green]
                      > > Your problem is not the escape character, and it has nothing to do with
                      > > "pure" ASCII XML text. If your stored procedure has no errors and you[/color][/color]
                      are[color=blue][color=green]
                      > > passing your parameter properly, it should work without any problems.[/color][/color]
                      Here[color=blue][color=green]
                      > > is the code that I tried and it worked.
                      > >
                      > > private SqlParameter CreateParameter (string sName, SqlDbType lType, int
                      > > iSize, ParameterDirect ion lDir,
                      > >
                      > > bool bNullable, string sValue)
                      > >
                      > > {
                      > >
                      > > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                      > >
                      > > oParameter.Size = iSize;
                      > >
                      > > oParameter.Dire ction = lDir;
                      > >
                      > > oParameter.IsNu llable = bNullable;
                      > >
                      > > oParameter.Valu e = sValue;
                      > >
                      > > return oParameter;
                      > >
                      > > }
                      > >
                      > > private void button1_Click(o bject sender, System.EventArg s e)
                      > >
                      > > {
                      > >
                      > > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                      > > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                      > > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                      > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                      > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                      > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                      > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                      > >
                      > > SqlConnection oConn = new SqlConnection() ;
                      > >
                      > > SqlCommand oCmd = new SqlCommand();
                      > >
                      > > oConn.Connectio nString = "your connection string";
                      > >
                      > > try{oConn.Open( );}
                      > >
                      > > catch(Exception ex){string sException = ex.Message;};
                      > >
                      > > oCmd.Connection = oConn;
                      > >
                      > > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                      > >
                      > > oCmd.CommandTex t = "sp_Test";
                      > >
                      > > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900[/color][/color]
                      ,[color=blue][color=green]
                      > > ParameterDirect ion.Input,
                      > >
                      > > false, sString));
                      > >
                      > > try
                      > >
                      > > {
                      > >
                      > > oCmd.ExecuteNon Query();
                      > >
                      > > }
                      > >
                      > > catch(System.Ex ception ex){string sException = ex.Message;}
                      > >
                      > > oConn.Close();
                      > >
                      > > oCmd.Dispose(); oConn.Dispose() ;
                      > >
                      > > }
                      > >
                      > >
                      > >
                      > > Here is the stored provedure:
                      > >
                      > > CREATE PROCEDURE sp_Test
                      > >
                      > > @StringIn varchar(900)
                      > > AS
                      > > DECLARE @hdoc int
                      > > --Create an internal representation of the XML document.
                      > > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                      > > EXEC sp_xml_removedo cument @hDoc
                      > >
                      > > GO
                      > >
                      > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                      > > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=darkred]
                      > > > No--it does not work. That is why I posted the message.
                      > > >
                      > > > SQL Server reports:
                      > > >
                      > > > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
                      > > Line[color=darkred]
                      > > > 27
                      > > >
                      > > > XML parsing error: A string literal was expected, but no opening quote
                      > > > character was found.
                      > > >
                      > > >
                      > > > If anyone has any ideas on how to generate the "pure" ASCII XML text I
                      > > > requested, please let me know.
                      > > >
                      > > > Thanks,
                      > > > -- Steve
                      > > >
                      > > > "dd" <someone@somewh ere.com> wrote in message
                      > > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...
                      > > > > It is the C# escape character, i.e. "\", as well as C and C++.
                      > > > > You do not have to replace it with anythng. Just leave it.
                      > > > > Just pass it to your stored procedure as is, it will work OK.
                      > > > >
                      > > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                      > > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                      > > > > > Hello,
                      > > > > >
                      > > > > > I have built an XMLDocument object instance and I get the[/color][/color][/color]
                      following[color=blue][color=green][color=darkred]
                      > > > string
                      > > > > > when I examine the InnerXml property:
                      > > > > >
                      > > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                      > > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                      > > > > QID=\"55112\">< Tag2
                      > > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                      > > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                      > > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                      > > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                      > > > > >
                      > > > > > Notice that the double quotes are all escaped--that is they appear[/color][/color]
                      > as[color=green][color=darkred]
                      > > > > >
                      > > > > > \"
                      > > > > >
                      > > > > > versus
                      > > > > >
                      > > > > > "
                      > > > > >
                      > > > > > I would like to "transform" or "convert" this string into a string[/color][/color]
                      > in[color=green][color=darkred]
                      > > > > which
                      > > > > > the escape characters are "converted" . This would generate a[/color][/color][/color]
                      string[color=blue][color=green]
                      > > that[color=darkred]
                      > > > > > would appear like this:
                      > > > > >
                      > > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1
                      > > > QID="55111"><Ta g2
                      > > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                      > > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                      > > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                      > > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                      > > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                      > > > > >
                      > > > > > I do not want to use a search/replace algorithm because I cannot[/color][/color][/color]
                      be[color=blue][color=green][color=darkred]
                      > > > > entirely
                      > > > > > sure that there will not be escape sequences other than \" in the
                      > > > string.
                      > > > > I
                      > > > > > am actually seeking a solution that would "transform" the \" to "[/color][/color]
                      > (as[color=green]
                      > > I[color=darkred]
                      > > > > > require) but also one that would convert \n to ASCII 10 and \r to[/color]
                      > > ASCII[color=darkred]
                      > > > > 13.
                      > > > > > In other words, I would like to convert the escape-encoded string[/color][/color][/color]
                      to[color=blue]
                      > a[color=green][color=darkred]
                      > > > > > standard ASCII string.
                      > > > > >
                      > > > > > Moreover, why does the XMLDocument's InnerXml return an[/color][/color]
                      > escape-encoded[color=green][color=darkred]
                      > > > > > string instead of a "straight" (unencoded) string? Is there a way[/color][/color][/color]
                      to[color=blue][color=green]
                      > > get[color=darkred]
                      > > > > the
                      > > > > > InnerXml to return the "straight" string? I plan to pass the XML[/color]
                      > > string[color=darkred]
                      > > > as
                      > > > > > an argument to a Sql stored procedure; therefore, the encoded[/color][/color][/color]
                      string[color=blue][color=green][color=darkred]
                      > > > does
                      > > > > > not work--I must use the unencoded version. Certainly others have
                      > > > > > encountered this problem--I just could not find a single solution[/color][/color]
                      > and[color=green]
                      > > I[color=darkred]
                      > > > > > spend hours searching MSDN and Google! For example, I read some[/color][/color]
                      > other[color=green][color=darkred]
                      > > > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color]
                      > > them[color=darkred]
                      > > > > > actually explained how to do it--and pseudocode can only be so[/color]
                      > > useful...[color=darkred]
                      > > > > >
                      > > > > > Thank you in advance for any assistance. I will confirm whether[/color][/color][/color]
                      any[color=blue][color=green][color=darkred]
                      > > > > > suggestions work.
                      > > > > >
                      > > > > > Regards,
                      > > > > > Steve
                      > > > > >
                      > > > > >
                      > > > > >
                      > > > > >
                      > > > > >
                      > > > > >
                      > > > >
                      > > > >
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • Steve Litvack

                        #12
                        Re: Unwanted Escape Codes In String...

                        Thank you again for your help, but when we try your example we still get the
                        parsing error. Perhaps you have a difference SQL Server setting or DB
                        setting from us? We're using Sql Server 2000.

                        Regards,
                        -- Steve

                        "dd" <someone@somewh ere.com> wrote in message
                        news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=blue]
                        > Your problem is not the escape character, and it has nothing to do with
                        > "pure" ASCII XML text. If your stored procedure has no errors and you are
                        > passing your parameter properly, it should work without any problems. Here
                        > is the code that I tried and it worked.
                        >
                        > private SqlParameter CreateParameter (string sName, SqlDbType lType, int
                        > iSize, ParameterDirect ion lDir,
                        >
                        > bool bNullable, string sValue)
                        >
                        > {
                        >
                        > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                        >
                        > oParameter.Size = iSize;
                        >
                        > oParameter.Dire ction = lDir;
                        >
                        > oParameter.IsNu llable = bNullable;
                        >
                        > oParameter.Valu e = sValue;
                        >
                        > return oParameter;
                        >
                        > }
                        >
                        > private void button1_Click(o bject sender, System.EventArg s e)
                        >
                        > {
                        >
                        > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                        > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                        > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                        > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                        > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                        > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                        > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                        >
                        > SqlConnection oConn = new SqlConnection() ;
                        >
                        > SqlCommand oCmd = new SqlCommand();
                        >
                        > oConn.Connectio nString = "your connection string";
                        >
                        > try{oConn.Open( );}
                        >
                        > catch(Exception ex){string sException = ex.Message;};
                        >
                        > oCmd.Connection = oConn;
                        >
                        > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                        >
                        > oCmd.CommandTex t = "sp_Test";
                        >
                        > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900 ,
                        > ParameterDirect ion.Input,
                        >
                        > false, sString));
                        >
                        > try
                        >
                        > {
                        >
                        > oCmd.ExecuteNon Query();
                        >
                        > }
                        >
                        > catch(System.Ex ception ex){string sException = ex.Message;}
                        >
                        > oConn.Close();
                        >
                        > oCmd.Dispose(); oConn.Dispose() ;
                        >
                        > }
                        >
                        >
                        >
                        > Here is the stored provedure:
                        >
                        > CREATE PROCEDURE sp_Test
                        >
                        > @StringIn varchar(900)
                        > AS
                        > DECLARE @hdoc int
                        > --Create an internal representation of the XML document.
                        > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                        > EXEC sp_xml_removedo cument @hDoc
                        >
                        > GO
                        >
                        > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                        > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=green]
                        > > No--it does not work. That is why I posted the message.
                        > >
                        > > SQL Server reports:
                        > >
                        > > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
                        > Line[color=green]
                        > > 27
                        > >
                        > > XML parsing error: A string literal was expected, but no opening quote
                        > > character was found.
                        > >
                        > >
                        > > If anyone has any ideas on how to generate the "pure" ASCII XML text I
                        > > requested, please let me know.
                        > >
                        > > Thanks,
                        > > -- Steve
                        > >
                        > > "dd" <someone@somewh ere.com> wrote in message
                        > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=darkred]
                        > > > It is the C# escape character, i.e. "\", as well as C and C++.
                        > > > You do not have to replace it with anythng. Just leave it.
                        > > > Just pass it to your stored procedure as is, it will work OK.
                        > > >
                        > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                        > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                        > > > > Hello,
                        > > > >
                        > > > > I have built an XMLDocument object instance and I get the following[/color]
                        > > string[color=darkred]
                        > > > > when I examine the InnerXml property:
                        > > > >
                        > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                        > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                        > > > QID=\"55112\">< Tag2
                        > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                        > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                        > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                        > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                        > > > >
                        > > > > Notice that the double quotes are all escaped--that is they appear[/color][/color][/color]
                        as[color=blue][color=green][color=darkred]
                        > > > >
                        > > > > \"
                        > > > >
                        > > > > versus
                        > > > >
                        > > > > "
                        > > > >
                        > > > > I would like to "transform" or "convert" this string into a string[/color][/color][/color]
                        in[color=blue][color=green][color=darkred]
                        > > > which
                        > > > > the escape characters are "converted" . This would generate a string[/color][/color]
                        > that[color=green][color=darkred]
                        > > > > would appear like this:
                        > > > >
                        > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color]
                        > > QID="55111"><Ta g2[color=darkred]
                        > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                        > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                        > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                        > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                        > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                        > > > >
                        > > > > I do not want to use a search/replace algorithm because I cannot be
                        > > > entirely
                        > > > > sure that there will not be escape sequences other than \" in the[/color]
                        > > string.[color=darkred]
                        > > > I
                        > > > > am actually seeking a solution that would "transform" the \" to "[/color][/color][/color]
                        (as[color=blue]
                        > I[color=green][color=darkred]
                        > > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color]
                        > ASCII[color=green][color=darkred]
                        > > > 13.
                        > > > > In other words, I would like to convert the escape-encoded string to[/color][/color][/color]
                        a[color=blue][color=green][color=darkred]
                        > > > > standard ASCII string.
                        > > > >
                        > > > > Moreover, why does the XMLDocument's InnerXml return an[/color][/color][/color]
                        escape-encoded[color=blue][color=green][color=darkred]
                        > > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color]
                        > get[color=green][color=darkred]
                        > > > the
                        > > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color]
                        > string[color=green]
                        > > as[color=darkred]
                        > > > > an argument to a Sql stored procedure; therefore, the encoded string[/color]
                        > > does[color=darkred]
                        > > > > not work--I must use the unencoded version. Certainly others have
                        > > > > encountered this problem--I just could not find a single solution[/color][/color][/color]
                        and[color=blue]
                        > I[color=green][color=darkred]
                        > > > > spend hours searching MSDN and Google! For example, I read some[/color][/color][/color]
                        other[color=blue][color=green][color=darkred]
                        > > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color]
                        > them[color=green][color=darkred]
                        > > > > actually explained how to do it--and pseudocode can only be so[/color][/color]
                        > useful...[color=green][color=darkred]
                        > > > >
                        > > > > Thank you in advance for any assistance. I will confirm whether any
                        > > > > suggestions work.
                        > > > >
                        > > > > Regards,
                        > > > > Steve
                        > > > >
                        > > > >
                        > > > >
                        > > > >
                        > > > >
                        > > > >
                        > > >
                        > > >[/color]
                        > >
                        > >[/color]
                        >
                        >[/color]


                        Comment

                        • Steve Litvack

                          #13
                          Re: Unwanted Escape Codes In String...

                          Thank you again for your help, but when we try your example we still get the
                          parsing error. Perhaps you have a difference SQL Server setting or DB
                          setting from us? We're using Sql Server 2000.

                          Regards,
                          -- Steve

                          "dd" <someone@somewh ere.com> wrote in message
                          news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=blue]
                          > Your problem is not the escape character, and it has nothing to do with
                          > "pure" ASCII XML text. If your stored procedure has no errors and you are
                          > passing your parameter properly, it should work without any problems. Here
                          > is the code that I tried and it worked.
                          >
                          > private SqlParameter CreateParameter (string sName, SqlDbType lType, int
                          > iSize, ParameterDirect ion lDir,
                          >
                          > bool bNullable, string sValue)
                          >
                          > {
                          >
                          > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                          >
                          > oParameter.Size = iSize;
                          >
                          > oParameter.Dire ction = lDir;
                          >
                          > oParameter.IsNu llable = bNullable;
                          >
                          > oParameter.Valu e = sValue;
                          >
                          > return oParameter;
                          >
                          > }
                          >
                          > private void button1_Click(o bject sender, System.EventArg s e)
                          >
                          > {
                          >
                          > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                          > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                          > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                          > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                          > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                          > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                          > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                          >
                          > SqlConnection oConn = new SqlConnection() ;
                          >
                          > SqlCommand oCmd = new SqlCommand();
                          >
                          > oConn.Connectio nString = "your connection string";
                          >
                          > try{oConn.Open( );}
                          >
                          > catch(Exception ex){string sException = ex.Message;};
                          >
                          > oCmd.Connection = oConn;
                          >
                          > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                          >
                          > oCmd.CommandTex t = "sp_Test";
                          >
                          > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar, 900 ,
                          > ParameterDirect ion.Input,
                          >
                          > false, sString));
                          >
                          > try
                          >
                          > {
                          >
                          > oCmd.ExecuteNon Query();
                          >
                          > }
                          >
                          > catch(System.Ex ception ex){string sException = ex.Message;}
                          >
                          > oConn.Close();
                          >
                          > oCmd.Dispose(); oConn.Dispose() ;
                          >
                          > }
                          >
                          >
                          >
                          > Here is the stored provedure:
                          >
                          > CREATE PROCEDURE sp_Test
                          >
                          > @StringIn varchar(900)
                          > AS
                          > DECLARE @hdoc int
                          > --Create an internal representation of the XML document.
                          > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                          > EXEC sp_xml_removedo cument @hDoc
                          >
                          > GO
                          >
                          > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                          > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...[color=green]
                          > > No--it does not work. That is why I posted the message.
                          > >
                          > > SQL Server reports:
                          > >
                          > > Server: Msg 6603, Level 16, State 1, Procedure sp_xml_prepared ocument,[/color]
                          > Line[color=green]
                          > > 27
                          > >
                          > > XML parsing error: A string literal was expected, but no opening quote
                          > > character was found.
                          > >
                          > >
                          > > If anyone has any ideas on how to generate the "pure" ASCII XML text I
                          > > requested, please let me know.
                          > >
                          > > Thanks,
                          > > -- Steve
                          > >
                          > > "dd" <someone@somewh ere.com> wrote in message
                          > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...[color=darkred]
                          > > > It is the C# escape character, i.e. "\", as well as C and C++.
                          > > > You do not have to replace it with anythng. Just leave it.
                          > > > Just pass it to your stored procedure as is, it will work OK.
                          > > >
                          > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                          > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                          > > > > Hello,
                          > > > >
                          > > > > I have built an XMLDocument object instance and I get the following[/color]
                          > > string[color=darkred]
                          > > > > when I examine the InnerXml property:
                          > > > >
                          > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                          > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                          > > > QID=\"55112\">< Tag2
                          > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                          > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                          > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                          > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                          > > > >
                          > > > > Notice that the double quotes are all escaped--that is they appear[/color][/color][/color]
                          as[color=blue][color=green][color=darkred]
                          > > > >
                          > > > > \"
                          > > > >
                          > > > > versus
                          > > > >
                          > > > > "
                          > > > >
                          > > > > I would like to "transform" or "convert" this string into a string[/color][/color][/color]
                          in[color=blue][color=green][color=darkred]
                          > > > which
                          > > > > the escape characters are "converted" . This would generate a string[/color][/color]
                          > that[color=green][color=darkred]
                          > > > > would appear like this:
                          > > > >
                          > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1[/color]
                          > > QID="55111"><Ta g2[color=darkred]
                          > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                          > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                          > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                          > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                          > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                          > > > >
                          > > > > I do not want to use a search/replace algorithm because I cannot be
                          > > > entirely
                          > > > > sure that there will not be escape sequences other than \" in the[/color]
                          > > string.[color=darkred]
                          > > > I
                          > > > > am actually seeking a solution that would "transform" the \" to "[/color][/color][/color]
                          (as[color=blue]
                          > I[color=green][color=darkred]
                          > > > > require) but also one that would convert \n to ASCII 10 and \r to[/color][/color]
                          > ASCII[color=green][color=darkred]
                          > > > 13.
                          > > > > In other words, I would like to convert the escape-encoded string to[/color][/color][/color]
                          a[color=blue][color=green][color=darkred]
                          > > > > standard ASCII string.
                          > > > >
                          > > > > Moreover, why does the XMLDocument's InnerXml return an[/color][/color][/color]
                          escape-encoded[color=blue][color=green][color=darkred]
                          > > > > string instead of a "straight" (unencoded) string? Is there a way to[/color][/color]
                          > get[color=green][color=darkred]
                          > > > the
                          > > > > InnerXml to return the "straight" string? I plan to pass the XML[/color][/color]
                          > string[color=green]
                          > > as[color=darkred]
                          > > > > an argument to a Sql stored procedure; therefore, the encoded string[/color]
                          > > does[color=darkred]
                          > > > > not work--I must use the unencoded version. Certainly others have
                          > > > > encountered this problem--I just could not find a single solution[/color][/color][/color]
                          and[color=blue]
                          > I[color=green][color=darkred]
                          > > > > spend hours searching MSDN and Google! For example, I read some[/color][/color][/color]
                          other[color=blue][color=green][color=darkred]
                          > > > > threads that suggest using ActiveXMessageF ormatter, but not one of[/color][/color]
                          > them[color=green][color=darkred]
                          > > > > actually explained how to do it--and pseudocode can only be so[/color][/color]
                          > useful...[color=green][color=darkred]
                          > > > >
                          > > > > Thank you in advance for any assistance. I will confirm whether any
                          > > > > suggestions work.
                          > > > >
                          > > > > Regards,
                          > > > > Steve
                          > > > >
                          > > > >
                          > > > >
                          > > > >
                          > > > >
                          > > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          • Steve Litvack

                            #14
                            Re: Unwanted Escape Codes In String...

                            OK--I will try your exact code and will let you know (this message follows
                            my other recent message that reported that we're still getting errors).

                            Thanks,
                            Steve

                            "dd" <someone@somewh ere.com> wrote in message
                            news:lY0Xa.7446 $mv6.1331195@ne ws20.bellglobal .com...[color=blue]
                            > Steve,
                            > If you pass your string, which is a string that contains escape codes,[/color]
                            using[color=blue]
                            > Command Parameters it will work OK.
                            > The escape characters will be taken care of by the parameter object, and[/color]
                            the[color=blue]
                            > string will be passed to the stored procedure as it is supposed to be,[/color]
                            i.e.[color=blue]
                            > no escape characters will be passed to the stored procedure. Consequently,
                            > XMLDoc object inside your stored procedure will take it. Just use
                            > parameters, that's all.
                            >
                            > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                            > news:_y0Xa.1484 70$xg5.27620@tw ister.austin.rr .com...[color=green]
                            > > OK... This obviously is one of those problems where the stored proc[/color][/color]
                            works[color=blue][color=green]
                            > > with "well-formed" (what I call "pure") XML yet does not work with XML
                            > > containing escape sequences. This made it appear to be a problem with[/color][/color]
                            the[color=blue][color=green]
                            > > XML I'm using. However, thanks to your efforts you have convinced me[/color][/color]
                            that[color=blue][color=green]
                            > > the problem can also be fixed by reviewing the stored proc and leaving[/color][/color]
                            my[color=blue][color=green]
                            > > XML as-is. Thus, this problem seems to have two solutions: change the[/color][/color]
                            XML[color=blue]
                            > or[color=green]
                            > > change the sproc.
                            > >
                            > > I will do a little more research on this issue, study what you have[/color][/color]
                            kindly[color=blue][color=green]
                            > > written (and thank you for taking the time you clearly took), and I will
                            > > reply with either more information or with the solution(s) I have found.
                            > >
                            > > Regards,
                            > > -- Steve
                            > >
                            > > "dd" <someone@somewh ere.com> wrote in message
                            > > news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=darkred]
                            > > > Your problem is not the escape character, and it has nothing to do[/color][/color][/color]
                            with[color=blue][color=green][color=darkred]
                            > > > "pure" ASCII XML text. If your stored procedure has no errors and you[/color][/color]
                            > are[color=green][color=darkred]
                            > > > passing your parameter properly, it should work without any problems.[/color][/color]
                            > Here[color=green][color=darkred]
                            > > > is the code that I tried and it worked.
                            > > >
                            > > > private SqlParameter CreateParameter (string sName, SqlDbType lType,[/color][/color][/color]
                            int[color=blue][color=green][color=darkred]
                            > > > iSize, ParameterDirect ion lDir,
                            > > >
                            > > > bool bNullable, string sValue)
                            > > >
                            > > > {
                            > > >
                            > > > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                            > > >
                            > > > oParameter.Size = iSize;
                            > > >
                            > > > oParameter.Dire ction = lDir;
                            > > >
                            > > > oParameter.IsNu llable = bNullable;
                            > > >
                            > > > oParameter.Valu e = sValue;
                            > > >
                            > > > return oParameter;
                            > > >
                            > > > }
                            > > >
                            > > > private void button1_Click(o bject sender, System.EventArg s e)
                            > > >
                            > > > {
                            > > >
                            > > > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                            > > > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                            > > > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                            > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                            > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                            > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                            > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                            > > >
                            > > > SqlConnection oConn = new SqlConnection() ;
                            > > >
                            > > > SqlCommand oCmd = new SqlCommand();
                            > > >
                            > > > oConn.Connectio nString = "your connection string";
                            > > >
                            > > > try{oConn.Open( );}
                            > > >
                            > > > catch(Exception ex){string sException = ex.Message;};
                            > > >
                            > > > oCmd.Connection = oConn;
                            > > >
                            > > > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                            > > >
                            > > > oCmd.CommandTex t = "sp_Test";
                            > > >
                            > > > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar,[/color][/color][/color]
                            900[color=blue]
                            > ,[color=green][color=darkred]
                            > > > ParameterDirect ion.Input,
                            > > >
                            > > > false, sString));
                            > > >
                            > > > try
                            > > >
                            > > > {
                            > > >
                            > > > oCmd.ExecuteNon Query();
                            > > >
                            > > > }
                            > > >
                            > > > catch(System.Ex ception ex){string sException = ex.Message;}
                            > > >
                            > > > oConn.Close();
                            > > >
                            > > > oCmd.Dispose(); oConn.Dispose() ;
                            > > >
                            > > > }
                            > > >
                            > > >
                            > > >
                            > > > Here is the stored provedure:
                            > > >
                            > > > CREATE PROCEDURE sp_Test
                            > > >
                            > > > @StringIn varchar(900)
                            > > > AS
                            > > > DECLARE @hdoc int
                            > > > --Create an internal representation of the XML document.
                            > > > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                            > > > EXEC sp_xml_removedo cument @hDoc
                            > > >
                            > > > GO
                            > > >
                            > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                            > > > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...
                            > > > > No--it does not work. That is why I posted the message.
                            > > > >
                            > > > > SQL Server reports:
                            > > > >
                            > > > > Server: Msg 6603, Level 16, State 1, Procedure[/color][/color][/color]
                            sp_xml_prepared ocument,[color=blue][color=green][color=darkred]
                            > > > Line
                            > > > > 27
                            > > > >
                            > > > > XML parsing error: A string literal was expected, but no opening[/color][/color][/color]
                            quote[color=blue][color=green][color=darkred]
                            > > > > character was found.
                            > > > >
                            > > > >
                            > > > > If anyone has any ideas on how to generate the "pure" ASCII XML text[/color][/color][/color]
                            I[color=blue][color=green][color=darkred]
                            > > > > requested, please let me know.
                            > > > >
                            > > > > Thanks,
                            > > > > -- Steve
                            > > > >
                            > > > > "dd" <someone@somewh ere.com> wrote in message
                            > > > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...
                            > > > > > It is the C# escape character, i.e. "\", as well as C and C++.
                            > > > > > You do not have to replace it with anythng. Just leave it.
                            > > > > > Just pass it to your stored procedure as is, it will work OK.
                            > > > > >
                            > > > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                            > > > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                            > > > > > > Hello,
                            > > > > > >
                            > > > > > > I have built an XMLDocument object instance and I get the[/color][/color]
                            > following[color=green][color=darkred]
                            > > > > string
                            > > > > > > when I examine the InnerXml property:
                            > > > > > >
                            > > > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                            > > > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                            > > > > > QID=\"55112\">< Tag2
                            > > > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                            > > > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                            > > > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                            > > > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                            > > > > > >
                            > > > > > > Notice that the double quotes are all escaped--that is they[/color][/color][/color]
                            appear[color=blue][color=green]
                            > > as[color=darkred]
                            > > > > > >
                            > > > > > > \"
                            > > > > > >
                            > > > > > > versus
                            > > > > > >
                            > > > > > > "
                            > > > > > >
                            > > > > > > I would like to "transform" or "convert" this string into a[/color][/color][/color]
                            string[color=blue][color=green]
                            > > in[color=darkred]
                            > > > > > which
                            > > > > > > the escape characters are "converted" . This would generate a[/color][/color]
                            > string[color=green][color=darkred]
                            > > > that
                            > > > > > > would appear like this:
                            > > > > > >
                            > > > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1
                            > > > > QID="55111"><Ta g2
                            > > > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                            > > > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                            > > > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                            > > > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                            > > > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                            > > > > > >
                            > > > > > > I do not want to use a search/replace algorithm because I cannot[/color][/color]
                            > be[color=green][color=darkred]
                            > > > > > entirely
                            > > > > > > sure that there will not be escape sequences other than \" in[/color][/color][/color]
                            the[color=blue][color=green][color=darkred]
                            > > > > string.
                            > > > > > I
                            > > > > > > am actually seeking a solution that would "transform" the \" to[/color][/color][/color]
                            "[color=blue][color=green]
                            > > (as[color=darkred]
                            > > > I
                            > > > > > > require) but also one that would convert \n to ASCII 10 and \r[/color][/color][/color]
                            to[color=blue][color=green][color=darkred]
                            > > > ASCII
                            > > > > > 13.
                            > > > > > > In other words, I would like to convert the escape-encoded[/color][/color][/color]
                            string[color=blue]
                            > to[color=green]
                            > > a[color=darkred]
                            > > > > > > standard ASCII string.
                            > > > > > >
                            > > > > > > Moreover, why does the XMLDocument's InnerXml return an[/color]
                            > > escape-encoded[color=darkred]
                            > > > > > > string instead of a "straight" (unencoded) string? Is there a[/color][/color][/color]
                            way[color=blue]
                            > to[color=green][color=darkred]
                            > > > get
                            > > > > > the
                            > > > > > > InnerXml to return the "straight" string? I plan to pass the XML
                            > > > string
                            > > > > as
                            > > > > > > an argument to a Sql stored procedure; therefore, the encoded[/color][/color]
                            > string[color=green][color=darkred]
                            > > > > does
                            > > > > > > not work--I must use the unencoded version. Certainly others[/color][/color][/color]
                            have[color=blue][color=green][color=darkred]
                            > > > > > > encountered this problem--I just could not find a single[/color][/color][/color]
                            solution[color=blue][color=green]
                            > > and[color=darkred]
                            > > > I
                            > > > > > > spend hours searching MSDN and Google! For example, I read some[/color]
                            > > other[color=darkred]
                            > > > > > > threads that suggest using ActiveXMessageF ormatter, but not one[/color][/color][/color]
                            of[color=blue][color=green][color=darkred]
                            > > > them
                            > > > > > > actually explained how to do it--and pseudocode can only be so
                            > > > useful...
                            > > > > > >
                            > > > > > > Thank you in advance for any assistance. I will confirm whether[/color][/color]
                            > any[color=green][color=darkred]
                            > > > > > > suggestions work.
                            > > > > > >
                            > > > > > > Regards,
                            > > > > > > Steve
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > > >
                            > > > > >
                            > > > > >
                            > > > >
                            > > > >
                            > > >
                            > > >[/color]
                            > >
                            > >[/color]
                            >
                            >[/color]


                            Comment

                            • Steve Litvack

                              #15
                              Re: Unwanted Escape Codes In String...

                              OK--I will try your exact code and will let you know (this message follows
                              my other recent message that reported that we're still getting errors).

                              Thanks,
                              Steve

                              "dd" <someone@somewh ere.com> wrote in message
                              news:lY0Xa.7446 $mv6.1331195@ne ws20.bellglobal .com...[color=blue]
                              > Steve,
                              > If you pass your string, which is a string that contains escape codes,[/color]
                              using[color=blue]
                              > Command Parameters it will work OK.
                              > The escape characters will be taken care of by the parameter object, and[/color]
                              the[color=blue]
                              > string will be passed to the stored procedure as it is supposed to be,[/color]
                              i.e.[color=blue]
                              > no escape characters will be passed to the stored procedure. Consequently,
                              > XMLDoc object inside your stored procedure will take it. Just use
                              > parameters, that's all.
                              >
                              > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                              > news:_y0Xa.1484 70$xg5.27620@tw ister.austin.rr .com...[color=green]
                              > > OK... This obviously is one of those problems where the stored proc[/color][/color]
                              works[color=blue][color=green]
                              > > with "well-formed" (what I call "pure") XML yet does not work with XML
                              > > containing escape sequences. This made it appear to be a problem with[/color][/color]
                              the[color=blue][color=green]
                              > > XML I'm using. However, thanks to your efforts you have convinced me[/color][/color]
                              that[color=blue][color=green]
                              > > the problem can also be fixed by reviewing the stored proc and leaving[/color][/color]
                              my[color=blue][color=green]
                              > > XML as-is. Thus, this problem seems to have two solutions: change the[/color][/color]
                              XML[color=blue]
                              > or[color=green]
                              > > change the sproc.
                              > >
                              > > I will do a little more research on this issue, study what you have[/color][/color]
                              kindly[color=blue][color=green]
                              > > written (and thank you for taking the time you clearly took), and I will
                              > > reply with either more information or with the solution(s) I have found.
                              > >
                              > > Regards,
                              > > -- Steve
                              > >
                              > > "dd" <someone@somewh ere.com> wrote in message
                              > > news:Nu%Wa.7421 $mv6.1313243@ne ws20.bellglobal .com...[color=darkred]
                              > > > Your problem is not the escape character, and it has nothing to do[/color][/color][/color]
                              with[color=blue][color=green][color=darkred]
                              > > > "pure" ASCII XML text. If your stored procedure has no errors and you[/color][/color]
                              > are[color=green][color=darkred]
                              > > > passing your parameter properly, it should work without any problems.[/color][/color]
                              > Here[color=green][color=darkred]
                              > > > is the code that I tried and it worked.
                              > > >
                              > > > private SqlParameter CreateParameter (string sName, SqlDbType lType,[/color][/color][/color]
                              int[color=blue][color=green][color=darkred]
                              > > > iSize, ParameterDirect ion lDir,
                              > > >
                              > > > bool bNullable, string sValue)
                              > > >
                              > > > {
                              > > >
                              > > > SqlParameter oParameter = new SqlParameter(sN ame, lType);
                              > > >
                              > > > oParameter.Size = iSize;
                              > > >
                              > > > oParameter.Dire ction = lDir;
                              > > >
                              > > > oParameter.IsNu llable = bNullable;
                              > > >
                              > > > oParameter.Valu e = sValue;
                              > > >
                              > > > return oParameter;
                              > > >
                              > > > }
                              > > >
                              > > > private void button1_Click(o bject sender, System.EventArg s e)
                              > > >
                              > > > {
                              > > >
                              > > > string sString = "<?xml version=\"1.0\" ?><ROOT><UserDa ta
                              > > > UserID=\"2282\" ><Tag1 QID=\"55111\">< Tag2
                              > > > AID=\"5511101\" ></Tag2></Tag1><Tag1 QID=\"55112\">< Tag2
                              > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                              > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                              > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                              > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>";
                              > > >
                              > > > SqlConnection oConn = new SqlConnection() ;
                              > > >
                              > > > SqlCommand oCmd = new SqlCommand();
                              > > >
                              > > > oConn.Connectio nString = "your connection string";
                              > > >
                              > > > try{oConn.Open( );}
                              > > >
                              > > > catch(Exception ex){string sException = ex.Message;};
                              > > >
                              > > > oCmd.Connection = oConn;
                              > > >
                              > > > oCmd.CommandTyp e = CommandType.Sto redProcedure;
                              > > >
                              > > > oCmd.CommandTex t = "sp_Test";
                              > > >
                              > > > oCmd.Parameters .Add(CreatePara meter("@StringI n", SqlDbType.VarCh ar,[/color][/color][/color]
                              900[color=blue]
                              > ,[color=green][color=darkred]
                              > > > ParameterDirect ion.Input,
                              > > >
                              > > > false, sString));
                              > > >
                              > > > try
                              > > >
                              > > > {
                              > > >
                              > > > oCmd.ExecuteNon Query();
                              > > >
                              > > > }
                              > > >
                              > > > catch(System.Ex ception ex){string sException = ex.Message;}
                              > > >
                              > > > oConn.Close();
                              > > >
                              > > > oCmd.Dispose(); oConn.Dispose() ;
                              > > >
                              > > > }
                              > > >
                              > > >
                              > > >
                              > > > Here is the stored provedure:
                              > > >
                              > > > CREATE PROCEDURE sp_Test
                              > > >
                              > > > @StringIn varchar(900)
                              > > > AS
                              > > > DECLARE @hdoc int
                              > > > --Create an internal representation of the XML document.
                              > > > EXEC sp_xml_prepared ocument @hdoc OUTPUT, @StringIn
                              > > > EXEC sp_xml_removedo cument @hDoc
                              > > >
                              > > > GO
                              > > >
                              > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                              > > > news:PsYWa.1483 29$xg5.38111@tw ister.austin.rr .com...
                              > > > > No--it does not work. That is why I posted the message.
                              > > > >
                              > > > > SQL Server reports:
                              > > > >
                              > > > > Server: Msg 6603, Level 16, State 1, Procedure[/color][/color][/color]
                              sp_xml_prepared ocument,[color=blue][color=green][color=darkred]
                              > > > Line
                              > > > > 27
                              > > > >
                              > > > > XML parsing error: A string literal was expected, but no opening[/color][/color][/color]
                              quote[color=blue][color=green][color=darkred]
                              > > > > character was found.
                              > > > >
                              > > > >
                              > > > > If anyone has any ideas on how to generate the "pure" ASCII XML text[/color][/color][/color]
                              I[color=blue][color=green][color=darkred]
                              > > > > requested, please let me know.
                              > > > >
                              > > > > Thanks,
                              > > > > -- Steve
                              > > > >
                              > > > > "dd" <someone@somewh ere.com> wrote in message
                              > > > > news:uSVWa.7119 $mv6.1270447@ne ws20.bellglobal .com...
                              > > > > > It is the C# escape character, i.e. "\", as well as C and C++.
                              > > > > > You do not have to replace it with anythng. Just leave it.
                              > > > > > Just pass it to your stored procedure as is, it will work OK.
                              > > > > >
                              > > > > > "Steve Litvack" <usa_NO8SPAM004 @yahoo.com> wrote in message
                              > > > > > news:RDVWa.1474 29$xg5.55548@tw ister.austin.rr .com...
                              > > > > > > Hello,
                              > > > > > >
                              > > > > > > I have built an XMLDocument object instance and I get the[/color][/color]
                              > following[color=green][color=darkred]
                              > > > > string
                              > > > > > > when I examine the InnerXml property:
                              > > > > > >
                              > > > > > > <?xml version=\"1.0\" ?><ROOT><UserDa ta UserID=\"2282\" ><Tag1
                              > > > > > > QID=\"55111\">< Tag2 AID=\"5511101\" ></Tag2></Tag1><Tag1
                              > > > > > QID=\"55112\">< Tag2
                              > > > > > > AID=\"5511217\" ></Tag2></Tag1><Tag1 QID=\"5512282\" ><Tag2
                              > > > > > > AID=\"551228206 \"></Tag2></Tag1><Tag1 QID=\"55114\">< Tag2
                              > > > > > > AID=\"5511406\" ></Tag2></Tag1><Tag1 QID=\"55115\">< Tag2
                              > > > > > > AID=\"5511505\" ></Tag2></Tag1></UserData></ROOT>
                              > > > > > >
                              > > > > > > Notice that the double quotes are all escaped--that is they[/color][/color][/color]
                              appear[color=blue][color=green]
                              > > as[color=darkred]
                              > > > > > >
                              > > > > > > \"
                              > > > > > >
                              > > > > > > versus
                              > > > > > >
                              > > > > > > "
                              > > > > > >
                              > > > > > > I would like to "transform" or "convert" this string into a[/color][/color][/color]
                              string[color=blue][color=green]
                              > > in[color=darkred]
                              > > > > > which
                              > > > > > > the escape characters are "converted" . This would generate a[/color][/color]
                              > string[color=green][color=darkred]
                              > > > that
                              > > > > > > would appear like this:
                              > > > > > >
                              > > > > > > <?xml version="1.0"?> <ROOT><UserDa ta UserID="2282">< Tag1
                              > > > > QID="55111"><Ta g2
                              > > > > > > AID="5511101"></Tag2></Tag1><Tag1 QID="55112"><Ta g2
                              > > > > > > AID="5511217"></Tag2></Tag1><Tag1 QID="5512282">< Tag2
                              > > > > > > AID="551228206" ></Tag2></Tag1><Tag1 QID="55114"><Ta g2
                              > > > > > > AID="5511406"></Tag2></Tag1><Tag1 QID="55115"><Ta g2
                              > > > > > > AID="5511505"></Tag2></Tag1></UserData></ROOT>
                              > > > > > >
                              > > > > > > I do not want to use a search/replace algorithm because I cannot[/color][/color]
                              > be[color=green][color=darkred]
                              > > > > > entirely
                              > > > > > > sure that there will not be escape sequences other than \" in[/color][/color][/color]
                              the[color=blue][color=green][color=darkred]
                              > > > > string.
                              > > > > > I
                              > > > > > > am actually seeking a solution that would "transform" the \" to[/color][/color][/color]
                              "[color=blue][color=green]
                              > > (as[color=darkred]
                              > > > I
                              > > > > > > require) but also one that would convert \n to ASCII 10 and \r[/color][/color][/color]
                              to[color=blue][color=green][color=darkred]
                              > > > ASCII
                              > > > > > 13.
                              > > > > > > In other words, I would like to convert the escape-encoded[/color][/color][/color]
                              string[color=blue]
                              > to[color=green]
                              > > a[color=darkred]
                              > > > > > > standard ASCII string.
                              > > > > > >
                              > > > > > > Moreover, why does the XMLDocument's InnerXml return an[/color]
                              > > escape-encoded[color=darkred]
                              > > > > > > string instead of a "straight" (unencoded) string? Is there a[/color][/color][/color]
                              way[color=blue]
                              > to[color=green][color=darkred]
                              > > > get
                              > > > > > the
                              > > > > > > InnerXml to return the "straight" string? I plan to pass the XML
                              > > > string
                              > > > > as
                              > > > > > > an argument to a Sql stored procedure; therefore, the encoded[/color][/color]
                              > string[color=green][color=darkred]
                              > > > > does
                              > > > > > > not work--I must use the unencoded version. Certainly others[/color][/color][/color]
                              have[color=blue][color=green][color=darkred]
                              > > > > > > encountered this problem--I just could not find a single[/color][/color][/color]
                              solution[color=blue][color=green]
                              > > and[color=darkred]
                              > > > I
                              > > > > > > spend hours searching MSDN and Google! For example, I read some[/color]
                              > > other[color=darkred]
                              > > > > > > threads that suggest using ActiveXMessageF ormatter, but not one[/color][/color][/color]
                              of[color=blue][color=green][color=darkred]
                              > > > them
                              > > > > > > actually explained how to do it--and pseudocode can only be so
                              > > > useful...
                              > > > > > >
                              > > > > > > Thank you in advance for any assistance. I will confirm whether[/color][/color]
                              > any[color=green][color=darkred]
                              > > > > > > suggestions work.
                              > > > > > >
                              > > > > > > Regards,
                              > > > > > > Steve
                              > > > > > >
                              > > > > > >
                              > > > > > >
                              > > > > > >
                              > > > > > >
                              > > > > > >
                              > > > > >
                              > > > > >
                              > > > >
                              > > > >
                              > > >
                              > > >[/color]
                              > >
                              > >[/color]
                              >
                              >[/color]


                              Comment

                              Working...