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 18 7020
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
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
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
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
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
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
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 > > > > > >
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 > > > > > >
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 > > > > > > > > > > > > > >
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 > > > > > > > > > > > > > >
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 > > > > > >
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 > > > > > >
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 > > > > > > > > > > > > > > > > > > > > > > > >
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 > > > > > > > > > > > > > > > > > > > > > > > >
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 > > > > > > > > > > > > > >
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 > > > > > > > > > > > > > >
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.
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.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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. ...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
by: tammygombez |
last post by:
Hey fellow JavaFX developers,
I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
|
by: tammygombez |
last post by:
Hey everyone!
I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: CD Tom |
last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |