I am writing some XML data to the stringwriter. I want to pass the values in the stringwriter to the database but when I convert it to a string like
我正在给字符写入器写一些XML数据。我想将字符串写入器中的值传递给数据库,但是当我将其转换为类似的字符串时
StringWriter.GetStringBuilder().ToString() it is converting all the " (double quotes) to \"
StringWriter.GetStringBuilder()。ToString()它将所有“(双引号)”转换为\“
So when I pass that to database as parameter and when I try to read the data using openXML it's throwing an error.
因此,当我将其作为参数传递给数据库时,当我尝试使用openXML读取数据时,它会抛出错误。
Is there any work around for this ?
这有什么工作吗?
I am using ASP.NET 2.0
SQl server 2005
我正在使用ASP.NET 2.0 SQl服务器2005
thanks!
谢谢!
1 个解决方案
#1
4
I strongly suspect that you're looking at the debugger. That will show the escaped form, but the quotes won't actually be in the string if they shouldn't be.
我强烈怀疑你在看调试器。这将显示转义的表单,但如果它们不应该,引号实际上不会在字符串中。
I suggest you log the string somehow - then you'll see the real data, and my guess is that it won't contain the backslashes - assuming you haven't written any backslashes to the StringWriter
to start with. How are you writing the data to the StringWriter
? Is it possible that your problems are further upstream? (If you're writing the XML manually, I'd strongly recommend that you use an XML API instead. It's much less error-prone.)
我建议你以某种方式记录字符串 - 然后你会看到真实的数据,我的猜测是它不会包含反斜杠 - 假设你没有写任何反斜杠到StringWriter开始。你是如何将数据写入StringWriter的?您的问题是否可能进一步上游? (如果您手动编写XML,我强烈建议您使用XML API。它更不容易出错。)
What error are you getting when trying to read the XML back? What does it look like in the database?
尝试读取XML时会出现什么错误?它在数据库中看起来像什么?
I can pretty much guarantee that the problem won't be in StringWriter
or StringBuilder
- they don't perform any escaping.
我几乎可以保证问题不会出现在StringWriter或StringBuilder中 - 它们不会执行任何转义。
On another note, is there any reason why you're calling GetStringBuilder().ToString()
instead of just ToString()
?
另一方面,你有没有理由调用GetStringBuilder()。ToString()而不仅仅是ToString()?
#1
4
I strongly suspect that you're looking at the debugger. That will show the escaped form, but the quotes won't actually be in the string if they shouldn't be.
我强烈怀疑你在看调试器。这将显示转义的表单,但如果它们不应该,引号实际上不会在字符串中。
I suggest you log the string somehow - then you'll see the real data, and my guess is that it won't contain the backslashes - assuming you haven't written any backslashes to the StringWriter
to start with. How are you writing the data to the StringWriter
? Is it possible that your problems are further upstream? (If you're writing the XML manually, I'd strongly recommend that you use an XML API instead. It's much less error-prone.)
我建议你以某种方式记录字符串 - 然后你会看到真实的数据,我的猜测是它不会包含反斜杠 - 假设你没有写任何反斜杠到StringWriter开始。你是如何将数据写入StringWriter的?您的问题是否可能进一步上游? (如果您手动编写XML,我强烈建议您使用XML API。它更不容易出错。)
What error are you getting when trying to read the XML back? What does it look like in the database?
尝试读取XML时会出现什么错误?它在数据库中看起来像什么?
I can pretty much guarantee that the problem won't be in StringWriter
or StringBuilder
- they don't perform any escaping.
我几乎可以保证问题不会出现在StringWriter或StringBuilder中 - 它们不会执行任何转义。
On another note, is there any reason why you're calling GetStringBuilder().ToString()
instead of just ToString()
?
另一方面,你有没有理由调用GetStringBuilder()。ToString()而不仅仅是ToString()?