473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unwanted Escape Codes In String...

Hello,

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

<?xml version=\"1.0\"?><ROOT><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


Nov 15 '05 #1
18 7137
dd
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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
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


Nov 15 '05 #2
dd
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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
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


Nov 15 '05 #3
dd
Can you post your SP code as well as the code that creates SP paramaters?

"Steve Litvack" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line 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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
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




Nov 15 '05 #4
dd
Can you post your SP code as well as the code that creates SP paramaters?

"Steve Litvack" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line 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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
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




Nov 15 '05 #5
dd
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line 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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
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




Nov 15 '05 #6
dd
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line 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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
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




Nov 15 '05 #7
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
> 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
>
>
>
>
>
>



Nov 15 '05 #8
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
> 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
>
>
>
>
>
>



Nov 15 '05 #9
dd
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" <us************@yahoo.com> wrote in message
news:_y********************@twister.austin.rr.com. ..
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
> news:RD********************@twister.austin.rr.com. ..
> > 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
> >
> >
> >
> >
> >
> >
>
>



Nov 15 '05 #10
dd
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" <us************@yahoo.com> wrote in message
news:_y********************@twister.austin.rr.com. ..
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
> news:RD********************@twister.austin.rr.com. ..
> > 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
> >
> >
> >
> >
> >
> >
>
>



Nov 15 '05 #11
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
> 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
>
>
>
>
>
>



Nov 15 '05 #12
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
news:RD********************@twister.austin.rr.com. ..
> 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
>
>
>
>
>
>



Nov 15 '05 #13
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" <so*****@somewhere.com> wrote in message
news:lY********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:_y********************@twister.austin.rr.com. ..
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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
sp_xml_preparedocument, Line
> 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" <so*****@somewhere.com> wrote in message
> news:uS********************@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" <us************@yahoo.com> wrote in message
> > news:RD********************@twister.austin.rr.com. ..
> > > 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
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>



Nov 15 '05 #14
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" <so*****@somewhere.com> wrote in message
news:lY********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:_y********************@twister.austin.rr.com. ..
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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
sp_xml_preparedocument, Line
> 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" <so*****@somewhere.com> wrote in message
> news:uS********************@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" <us************@yahoo.com> wrote in message
> > news:RD********************@twister.austin.rr.com. ..
> > > 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
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>



Nov 15 '05 #15
dd
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" <us************@yahoo.com> wrote in message
news:X_*********************@twister.austin.rr.com ...
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
> news:RD********************@twister.austin.rr.com. ..
> > 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
> >
> >
> >
> >
> >
> >
>
>



Nov 15 '05 #16
dd
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" <us************@yahoo.com> wrote in message
news:X_*********************@twister.austin.rr.com ...
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" <so*****@somewhere.com> wrote in message
news:Nu********************@news20.bellglobal.com. ..
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" <us************@yahoo.com> wrote in message
news:Ps********************@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 sp_xml_preparedocument, Line
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" <so*****@somewhere.com> wrote in message
news:uS********************@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" <us************@yahoo.com> wrote in message
> news:RD********************@twister.austin.rr.com. ..
> > 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
> >
> >
> >
> >
> >
> >
>
>



Nov 15 '05 #17
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:4p*****************@news20.bellglobal.com...
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.

Nov 15 '05 #18
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" <us************@yahoo.com> wrote in message
news:Ww*********************@twister.austin.rr.com ...
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:4p*****************@news20.bellglobal.com...
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.


Nov 15 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: yawnmoth | last post by:
say i have a for loop that would iterate through every character and put a space between every 80th one, in effect forcing word wrap to occur. this can be implemented easily using a regular...
2
by: Daniel | last post by:
I'm working with strings that contain xml escape codes, such as '0' and need a way in python to unescape these back to their ascii representation, such as '&' but can't seem to find a python method...
2
by: Felix | last post by:
If I set a breakpoint in visual studio 2000 and viewed a local variable (in the "locals" panel), I would see something like: sql | " SELECT Operator.FirstName, .... now I am using visual...
5
by: Steve Litvack | last post by:
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...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
0
by: Steve Litvack | last post by:
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...
4
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
3
by: Guadala Harry | last post by:
I'd like to know the answer to the following question so I can know what to expect with regard to other similar uses of escape characters and strings. While everything works fine - I'd like to know...
1
by: marcvill | last post by:
I need to send printer specific escape codes a printer for a POS register. Can anyone tell me how to send these codes to a printer using VB .NET and the Win32 spooler functions? I have looked at the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.