Connecting Tech Pros Worldwide Forums | Help | Site Map

Unwanted Escape Codes In String...

Steve Litvack
Guest
 
Posts: n/a
#1: Nov 15 '05
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><UserData 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><UserData 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>

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 ActiveXMessageFormatter, 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
Guest
 
Posts: n/a
#2: Nov 15 '05

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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
>
> 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#3: Nov 15 '05

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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
>
> 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#4: Nov 15 '05

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.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color][/color]
> QID="55111"><Tag2[color=green][color=darkred]
> > > 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>
> > >
> > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#5: Nov 15 '05

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.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color][/color]
> QID="55111"><Tag2[color=green][color=darkred]
> > > 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>
> > >
> > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#6: Nov 15 '05

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, ParameterDirection lDir,

bool bNullable, string sValue)

{

SqlParameter oParameter = new SqlParameter(sName, lType);

oParameter.Size = iSize;

oParameter.Direction = lDir;

oParameter.IsNullable = bNullable;

oParameter.Value = sValue;

return oParameter;

}

private void button1_Click(object sender, System.EventArgs e)

{

string sString = "<?xml version=\"1.0\"?><ROOT><UserData
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.ConnectionString = "your connection string";

try{oConn.Open();}

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

oCmd.Connection = oConn;

oCmd.CommandType = CommandType.StoredProcedure;

oCmd.CommandText = "sp_Test";

oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900 ,
ParameterDirection.Input,

false, sString));

try

{

oCmd.ExecuteNonQuery();

}

catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
EXEC sp_xml_removedocument @hDoc

GO

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color][/color]
> QID="55111"><Tag2[color=green][color=darkred]
> > > 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>
> > >
> > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#7: Nov 15 '05

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, ParameterDirection lDir,

bool bNullable, string sValue)

{

SqlParameter oParameter = new SqlParameter(sName, lType);

oParameter.Size = iSize;

oParameter.Direction = lDir;

oParameter.IsNullable = bNullable;

oParameter.Value = sValue;

return oParameter;

}

private void button1_Click(object sender, System.EventArgs e)

{

string sString = "<?xml version=\"1.0\"?><ROOT><UserData
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.ConnectionString = "your connection string";

try{oConn.Open();}

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

oCmd.Connection = oConn;

oCmd.CommandType = CommandType.StoredProcedure;

oCmd.CommandText = "sp_Test";

oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900 ,
ParameterDirection.Input,

false, sString));

try

{

oCmd.ExecuteNonQuery();

}

catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
EXEC sp_xml_removedocument @hDoc

GO

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color][/color]
> QID="55111"><Tag2[color=green][color=darkred]
> > > 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>
> > >
> > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#8: Nov 15 '05

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@somewhere.com> wrote in message
news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
>
> bool bNullable, string sValue)
>
> {
>
> SqlParameter oParameter = new SqlParameter(sName, lType);
>
> oParameter.Size = iSize;
>
> oParameter.Direction = lDir;
>
> oParameter.IsNullable = bNullable;
>
> oParameter.Value = sValue;
>
> return oParameter;
>
> }
>
> private void button1_Click(object sender, System.EventArgs e)
>
> {
>
> string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> 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.ConnectionString = "your connection string";
>
> try{oConn.Open();}
>
> catch(Exception ex){string sException = ex.Message;};
>
> oCmd.Connection = oConn;
>
> oCmd.CommandType = CommandType.StoredProcedure;
>
> oCmd.CommandText = "sp_Test";
>
> oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900 ,
> ParameterDirection.Input,
>
> false, sString));
>
> try
>
> {
>
> oCmd.ExecuteNonQuery();
>
> }
>
> catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> EXEC sp_xml_removedocument @hDoc
>
> GO
>
> "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color]
> > QID="55111"><Tag2[color=darkred]
> > > > 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>
> > > >
> > > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#9: Nov 15 '05

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@somewhere.com> wrote in message
news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
>
> bool bNullable, string sValue)
>
> {
>
> SqlParameter oParameter = new SqlParameter(sName, lType);
>
> oParameter.Size = iSize;
>
> oParameter.Direction = lDir;
>
> oParameter.IsNullable = bNullable;
>
> oParameter.Value = sValue;
>
> return oParameter;
>
> }
>
> private void button1_Click(object sender, System.EventArgs e)
>
> {
>
> string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> 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.ConnectionString = "your connection string";
>
> try{oConn.Open();}
>
> catch(Exception ex){string sException = ex.Message;};
>
> oCmd.Connection = oConn;
>
> oCmd.CommandType = CommandType.StoredProcedure;
>
> oCmd.CommandText = "sp_Test";
>
> oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900 ,
> ParameterDirection.Input,
>
> false, sString));
>
> try
>
> {
>
> oCmd.ExecuteNonQuery();
>
> }
>
> catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> EXEC sp_xml_removedocument @hDoc
>
> GO
>
> "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color]
> > QID="55111"><Tag2[color=darkred]
> > > > 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>
> > > >
> > > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#10: Nov 15 '05

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.148470$xg5.27620@twister.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@somewhere.com> wrote in message
> news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
> >
> > bool bNullable, string sValue)
> >
> > {
> >
> > SqlParameter oParameter = new SqlParameter(sName, lType);
> >
> > oParameter.Size = iSize;
> >
> > oParameter.Direction = lDir;
> >
> > oParameter.IsNullable = bNullable;
> >
> > oParameter.Value = sValue;
> >
> > return oParameter;
> >
> > }
> >
> > private void button1_Click(object sender, System.EventArgs e)
> >
> > {
> >
> > string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> > 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.ConnectionString = "your connection string";
> >
> > try{oConn.Open();}
> >
> > catch(Exception ex){string sException = ex.Message;};
> >
> > oCmd.Connection = oConn;
> >
> > oCmd.CommandType = CommandType.StoredProcedure;
> >
> > oCmd.CommandText = "sp_Test";
> >
> > oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900[/color][/color]
,[color=blue][color=green]
> > ParameterDirection.Input,
> >
> > false, sString));
> >
> > try
> >
> > {
> >
> > oCmd.ExecuteNonQuery();
> >
> > }
> >
> > catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> > EXEC sp_xml_removedocument @hDoc
> >
> > GO
> >
> > "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> > news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
> > > > >
> > > > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#11: Nov 15 '05

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.148470$xg5.27620@twister.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@somewhere.com> wrote in message
> news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
> >
> > bool bNullable, string sValue)
> >
> > {
> >
> > SqlParameter oParameter = new SqlParameter(sName, lType);
> >
> > oParameter.Size = iSize;
> >
> > oParameter.Direction = lDir;
> >
> > oParameter.IsNullable = bNullable;
> >
> > oParameter.Value = sValue;
> >
> > return oParameter;
> >
> > }
> >
> > private void button1_Click(object sender, System.EventArgs e)
> >
> > {
> >
> > string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> > 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.ConnectionString = "your connection string";
> >
> > try{oConn.Open();}
> >
> > catch(Exception ex){string sException = ex.Message;};
> >
> > oCmd.Connection = oConn;
> >
> > oCmd.CommandType = CommandType.StoredProcedure;
> >
> > oCmd.CommandText = "sp_Test";
> >
> > oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900[/color][/color]
,[color=blue][color=green]
> > ParameterDirection.Input,
> >
> > false, sString));
> >
> > try
> >
> > {
> >
> > oCmd.ExecuteNonQuery();
> >
> > }
> >
> > catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> > EXEC sp_xml_removedocument @hDoc
> >
> > GO
> >
> > "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> > news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
> > > > >
> > > > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#12: Nov 15 '05

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@somewhere.com> wrote in message
news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
>
> bool bNullable, string sValue)
>
> {
>
> SqlParameter oParameter = new SqlParameter(sName, lType);
>
> oParameter.Size = iSize;
>
> oParameter.Direction = lDir;
>
> oParameter.IsNullable = bNullable;
>
> oParameter.Value = sValue;
>
> return oParameter;
>
> }
>
> private void button1_Click(object sender, System.EventArgs e)
>
> {
>
> string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> 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.ConnectionString = "your connection string";
>
> try{oConn.Open();}
>
> catch(Exception ex){string sException = ex.Message;};
>
> oCmd.Connection = oConn;
>
> oCmd.CommandType = CommandType.StoredProcedure;
>
> oCmd.CommandText = "sp_Test";
>
> oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900 ,
> ParameterDirection.Input,
>
> false, sString));
>
> try
>
> {
>
> oCmd.ExecuteNonQuery();
>
> }
>
> catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> EXEC sp_xml_removedocument @hDoc
>
> GO
>
> "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color]
> > QID="55111"><Tag2[color=darkred]
> > > > 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>
> > > >
> > > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#13: Nov 15 '05

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@somewhere.com> wrote in message
news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
>
> bool bNullable, string sValue)
>
> {
>
> SqlParameter oParameter = new SqlParameter(sName, lType);
>
> oParameter.Size = iSize;
>
> oParameter.Direction = lDir;
>
> oParameter.IsNullable = bNullable;
>
> oParameter.Value = sValue;
>
> return oParameter;
>
> }
>
> private void button1_Click(object sender, System.EventArgs e)
>
> {
>
> string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> 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.ConnectionString = "your connection string";
>
> try{oConn.Open();}
>
> catch(Exception ex){string sException = ex.Message;};
>
> oCmd.Connection = oConn;
>
> oCmd.CommandType = CommandType.StoredProcedure;
>
> oCmd.CommandText = "sp_Test";
>
> oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900 ,
> ParameterDirection.Input,
>
> false, sString));
>
> try
>
> {
>
> oCmd.ExecuteNonQuery();
>
> }
>
> catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> EXEC sp_xml_removedocument @hDoc
>
> GO
>
> "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData UserID="2282"><Tag1[/color]
> > QID="55111"><Tag2[color=darkred]
> > > > 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>
> > > >
> > > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#14: Nov 15 '05

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@somewhere.com> wrote in message
news:lY0Xa.7446$mv6.1331195@news20.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.148470$xg5.27620@twister.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@somewhere.com> wrote in message
> > news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
> > >
> > > bool bNullable, string sValue)
> > >
> > > {
> > >
> > > SqlParameter oParameter = new SqlParameter(sName, lType);
> > >
> > > oParameter.Size = iSize;
> > >
> > > oParameter.Direction = lDir;
> > >
> > > oParameter.IsNullable = bNullable;
> > >
> > > oParameter.Value = sValue;
> > >
> > > return oParameter;
> > >
> > > }
> > >
> > > private void button1_Click(object sender, System.EventArgs e)
> > >
> > > {
> > >
> > > string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> > > 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.ConnectionString = "your connection string";
> > >
> > > try{oConn.Open();}
> > >
> > > catch(Exception ex){string sException = ex.Message;};
> > >
> > > oCmd.Connection = oConn;
> > >
> > > oCmd.CommandType = CommandType.StoredProcedure;
> > >
> > > oCmd.CommandText = "sp_Test";
> > >
> > > oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar,[/color][/color][/color]
900[color=blue]
> ,[color=green][color=darkred]
> > > ParameterDirection.Input,
> > >
> > > false, sString));
> > >
> > > try
> > >
> > > {
> > >
> > > oCmd.ExecuteNonQuery();
> > >
> > > }
> > >
> > > catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> > > EXEC sp_xml_removedocument @hDoc
> > >
> > > GO
> > >
> > > "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> > > news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[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@somewhere.com> wrote in message
> > > > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
> > > > > >
> > > > > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#15: Nov 15 '05

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@somewhere.com> wrote in message
news:lY0Xa.7446$mv6.1331195@news20.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.148470$xg5.27620@twister.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@somewhere.com> wrote in message
> > news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
> > >
> > > bool bNullable, string sValue)
> > >
> > > {
> > >
> > > SqlParameter oParameter = new SqlParameter(sName, lType);
> > >
> > > oParameter.Size = iSize;
> > >
> > > oParameter.Direction = lDir;
> > >
> > > oParameter.IsNullable = bNullable;
> > >
> > > oParameter.Value = sValue;
> > >
> > > return oParameter;
> > >
> > > }
> > >
> > > private void button1_Click(object sender, System.EventArgs e)
> > >
> > > {
> > >
> > > string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> > > 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.ConnectionString = "your connection string";
> > >
> > > try{oConn.Open();}
> > >
> > > catch(Exception ex){string sException = ex.Message;};
> > >
> > > oCmd.Connection = oConn;
> > >
> > > oCmd.CommandType = CommandType.StoredProcedure;
> > >
> > > oCmd.CommandText = "sp_Test";
> > >
> > > oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar,[/color][/color][/color]
900[color=blue]
> ,[color=green][color=darkred]
> > > ParameterDirection.Input,
> > >
> > > false, sString));
> > >
> > > try
> > >
> > > {
> > >
> > > oCmd.ExecuteNonQuery();
> > >
> > > }
> > >
> > > catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> > > EXEC sp_xml_removedocument @hDoc
> > >
> > > GO
> > >
> > > "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> > > news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[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@somewhere.com> wrote in message
> > > > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
> > > > > >
> > > > > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#16: Nov 15 '05

re: Unwanted Escape Codes In String...


I am running SQL Server 2000.
If you want you can post your code and the stored procedure. I will run it
on my machine, and we'll se what happens.

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:X_1Xa.148893$xg5.114891@twister.austin.rr.com ...[color=blue]
> Thank you again for your help, but when we try your example we still get[/color]
the[color=blue]
> 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@somewhere.com> wrote in message
> news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
> >
> > bool bNullable, string sValue)
> >
> > {
> >
> > SqlParameter oParameter = new SqlParameter(sName, lType);
> >
> > oParameter.Size = iSize;
> >
> > oParameter.Direction = lDir;
> >
> > oParameter.IsNullable = bNullable;
> >
> > oParameter.Value = sValue;
> >
> > return oParameter;
> >
> > }
> >
> > private void button1_Click(object sender, System.EventArgs e)
> >
> > {
> >
> > string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> > 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.ConnectionString = "your connection string";
> >
> > try{oConn.Open();}
> >
> > catch(Exception ex){string sException = ex.Message;};
> >
> > oCmd.Connection = oConn;
> >
> > oCmd.CommandType = CommandType.StoredProcedure;
> >
> > oCmd.CommandText = "sp_Test";
> >
> > oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900[/color][/color]
,[color=blue][color=green]
> > ParameterDirection.Input,
> >
> > false, sString));
> >
> > try
> >
> > {
> >
> > oCmd.ExecuteNonQuery();
> >
> > }
> >
> > catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> > EXEC sp_xml_removedocument @hDoc
> >
> > GO
> >
> > "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> > news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
> > > > >
> > > > > 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 ActiveXMessageFormatter, 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]


dd
Guest
 
Posts: n/a
#17: Nov 15 '05

re: Unwanted Escape Codes In String...


I am running SQL Server 2000.
If you want you can post your code and the stored procedure. I will run it
on my machine, and we'll se what happens.

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:X_1Xa.148893$xg5.114891@twister.austin.rr.com ...[color=blue]
> Thank you again for your help, but when we try your example we still get[/color]
the[color=blue]
> 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@somewhere.com> wrote in message
> news:Nu%Wa.7421$mv6.1313243@news20.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, ParameterDirection lDir,
> >
> > bool bNullable, string sValue)
> >
> > {
> >
> > SqlParameter oParameter = new SqlParameter(sName, lType);
> >
> > oParameter.Size = iSize;
> >
> > oParameter.Direction = lDir;
> >
> > oParameter.IsNullable = bNullable;
> >
> > oParameter.Value = sValue;
> >
> > return oParameter;
> >
> > }
> >
> > private void button1_Click(object sender, System.EventArgs e)
> >
> > {
> >
> > string sString = "<?xml version=\"1.0\"?><ROOT><UserData
> > 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.ConnectionString = "your connection string";
> >
> > try{oConn.Open();}
> >
> > catch(Exception ex){string sException = ex.Message;};
> >
> > oCmd.Connection = oConn;
> >
> > oCmd.CommandType = CommandType.StoredProcedure;
> >
> > oCmd.CommandText = "sp_Test";
> >
> > oCmd.Parameters.Add(CreateParameter("@StringIn", SqlDbType.VarChar, 900[/color][/color]
,[color=blue][color=green]
> > ParameterDirection.Input,
> >
> > false, sString));
> >
> > try
> >
> > {
> >
> > oCmd.ExecuteNonQuery();
> >
> > }
> >
> > catch(System.Exception 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_preparedocument @hdoc OUTPUT, @StringIn
> > EXEC sp_xml_removedocument @hDoc
> >
> > GO
> >
> > "Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
> > news:PsYWa.148329$xg5.38111@twister.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_preparedocument,[/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@somewhere.com> wrote in message
> > > news:uSVWa.7119$mv6.1270447@news20.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.147429$xg5.55548@twister.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><UserData 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><UserData 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>
> > > > >
> > > > > 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 ActiveXMessageFormatter, 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]


Steve Litvack
Guest
 
Posts: n/a
#18: Nov 15 '05

re: Unwanted Escape Codes In String...


Hello:

Well--you were right all along (I'm man enough to bow to you and apologize
for my earlier insistence that the escape codes were causing the problem).
There are two conclusions here:

1. Passing a C# string containing escape codes does indeed work. The reason
it did NOT work had to do with the fact that my XML tags were in mixed case
and the sproc was expecting all uppercase tag names. I suppose that the Sql
OLEDB driver converts C strings to Sql-compliant strings and effectively
removes the escape sequences?

2. When I was getting the error from SQL Server, I was running the sproc
from Query Analyzer and passing the escape-coded string there. Apparently,
Query Analyzer doesn't like such strings and generates a parsing error.

I discovered the problem by trying the XML string in Query Analyzer without
the escape codes. I did not get an error from the sproc, but the insert it
attempts was not done. Once I realized the XML case issue, I corrected it
and then sproc worked. Then I added back the escape codes and it failed in
Query Analyzer. However, the string with the corrected XML tags and with
escape codes worked when passed as a parameter from .Net.

I offer you my most sincere thanks for your persistence in helping to solve
this problem. You obviously took a lot of time to help, and I am most
greatful.

The only remaining question is: Why are those escape codes appearing in my
XML string? At this point this is obviously just an academic question...
However, I would be interested to know how to ensure that they don't appear
even though they are no longer an issue for Sql Server.

Thanks again...

Regards,
-- Steve

"dd" <aa@aa.com> wrote in message
news:4pcXa.205$pq5.75269@news20.bellglobal.com...[color=blue]
> I am running SQL Server 2000.
> If you want you can post your code and the stored procedure. I will run it
> on my machine, and we'll se what happens.
>[/color]


codewriter
Guest
 
Posts: n/a
#19: Nov 15 '05

re: Unwanted Escape Codes In String...


No prob.

The escape codes are intrinsic to C#, as well as to C and C++. Compiler
thinks that a double quote is a beginning or an end of a string. If there is
an escape character, the complier treats the following character
differently. The reason you see the escape character is that you are looking
at the string from within C# IDE. For example, try to save a string to a
text file, you will not see any escape characters:
string sString = "abc\"def";
StreamWriter oWriter = File.CreateText("E:\\aaa.txt");
oWriter.Write(sString);
oWriter.Close();

"Steve Litvack" <usa_NO8SPAM004@yahoo.com> wrote in message
news:WwmXa.134862$TJ.8062422@twister.austin.rr.com ...[color=blue]
> Hello:
>
> Well--you were right all along (I'm man enough to bow to you and apologize
> for my earlier insistence that the escape codes were causing the problem).
> There are two conclusions here:
>
> 1. Passing a C# string containing escape codes does indeed work. The[/color]
reason[color=blue]
> it did NOT work had to do with the fact that my XML tags were in mixed[/color]
case[color=blue]
> and the sproc was expecting all uppercase tag names. I suppose that the[/color]
Sql[color=blue]
> OLEDB driver converts C strings to Sql-compliant strings and effectively
> removes the escape sequences?
>
> 2. When I was getting the error from SQL Server, I was running the sproc
> from Query Analyzer and passing the escape-coded string there. Apparently,
> Query Analyzer doesn't like such strings and generates a parsing error.
>
> I discovered the problem by trying the XML string in Query Analyzer[/color]
without[color=blue]
> the escape codes. I did not get an error from the sproc, but the insert it
> attempts was not done. Once I realized the XML case issue, I corrected it
> and then sproc worked. Then I added back the escape codes and it failed in
> Query Analyzer. However, the string with the corrected XML tags and with
> escape codes worked when passed as a parameter from .Net.
>
> I offer you my most sincere thanks for your persistence in helping to[/color]
solve[color=blue]
> this problem. You obviously took a lot of time to help, and I am most
> greatful.
>
> The only remaining question is: Why are those escape codes appearing in my
> XML string? At this point this is obviously just an academic question...
> However, I would be interested to know how to ensure that they don't[/color]
appear[color=blue]
> even though they are no longer an issue for Sql Server.
>
> Thanks again...
>
> Regards,
> -- Steve
>
> "dd" <aa@aa.com> wrote in message
> news:4pcXa.205$pq5.75269@news20.bellglobal.com...[color=green]
> > I am running SQL Server 2000.
> > If you want you can post your code and the stored procedure. I will run[/color][/color]
it[color=blue][color=green]
> > on my machine, and we'll se what happens.
> >[/color]
>
>[/color]


Closed Thread


Similar C# / C Sharp bytes