- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在服务器端使用 .NET c# + 在客户端使用 GWT,我有一个 Web 表单,它接受用户输入,然后我从中构造一个 XML 字符串并将其存储在数据库中。然后我需要从数据库中读回它,通过 tcp 将它发送到手持设备并将它解析为 XElement。一切正常,直到您从 word 或 excel 中复制和粘贴文本,在这种情况下,当我尝试这样做时:
XElement.parse(str);
它抛出一个异常:
'.', hexadecimal value 0x00, is an invalid character. Line 132, position 111.
会导致此问题的示例字符是右撇号字符 (0x2019)。现在可能会有一大堆特殊字符可能从 excel/word 等复制粘贴。处理这个问题的最佳方法是什么?以下是我如何从流构造字符串:
protected CallResult callUsingSocketClass(string methodName, params Action<CallParameters>[] addParameters)
{ WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_ENTRY_EXIT, "++Call({0}, ...)", methodName);
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
CallParameters parameters = new CallParameters(this, methodName);
foreach (var addParameter in addParameters)
{
addParameter(parameters);
}
string post = this.CreatePost(parameters);
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC(Method={0}, host={1}, port={2}, post='{3}')", methodName, this.Host, this.Port, post);
byte[] postBytes = Encoding.UTF8.GetBytes(post);
//
// Send the request and wait for the reply.
//
char[] replyContentChars = null;
for (int attempts = 0; attempts < 3; attempts++)
{
Socket socket = null;
try
{
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC - creating socket for RPC call...");
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
string hostID = this.Host;
if (this.HostIPAddress != null)
{
hostID = this.HostIPAddress;
}
using (socket = this.connectToServer(hostID, this.Port))
{
if (socket == null)
{
return null;
}
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC - socket created!");
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC - communicating with server...");
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC - writing post...");
this.sendDataToServer(socket, postBytes);
int replyLength = -1;
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC - reading reply...");
using (var reader = this.receiveStreamFromServer(socket))
{
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
socket.Close();
socket = null;
return null;
}
}
for (; ; )
{
string lineRaw = reader.ReadLine().Trim();
string line = lineRaw.ToLowerInvariant();
if (line.StartsWith("content-length:"))
{
replyLength = int.Parse(line.Substring(15));
}
else if (line == "")
{
if (replyLength < 0)
{
throw new InvalidOperationException("Reply hasn't specified content-length");
}
break;
}
else
{
if (this.CookieJar != null)
{
this.CookieJar.ProcessFromServer(lineRaw);
}
}
}
// Content starts here
replyContentChars = new char[replyLength];
int replyRecv = 0;
do
{
int charsRecv = reader.Read(replyContentChars, replyRecv, replyLength - replyRecv);
if (charsRecv <= 0)
{
break;
}
replyRecv += charsRecv;
} while (replyRecv < replyLength);
//int charsRecv = reader.Read(replyContentChars, 0, replyLength);
if (replyRecv != replyLength)
{
untime.Logger.Logger.Error("Web Service call '{0}' received {1} bytes, header indicated {2} bytes", methodName, replyRecv, replyLength);
throw new InvalidOperationException(String.Format("Have not received all of reply data - received {0} bytes, expected {1}", replyRecv, replyLength));
}
}
socket.Close();
socket = null;
}
}
catch (Exception e)
{
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC - exception thrown - {0} [{1},{2}]", e.Message, e.Source, e.StackTrace);
}
finally
{
if (socket != null)
{
socket.Close();
socket = null;
}
}
if (replyContentChars != null)
{
break;
}
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
}
//
// Verify that data has been received.
//
if (replyContentChars == null)
{
return null;
}
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
//
// Process the received data.
//
string replyContent = new string(replyContentChars);
WebServicesClient.Debug.DebugMessage(WebServicesClient.Debug.MASK_RPC_CALL, "RPC(Method={0}, replyContent='{1}')", methodName, replyContent);
XElement xReplyContent = XElement.Parse(replyContent);
var xReplyBody = xReplyContent.Element(nsSoap + "Body");
var xFault = xReplyBody.Element(nsSoap + "Fault");
if (xFault != null)
{
// Something has gone wrong on the server
var xFaultCode = xFault.Element(nsSoap + "Code");
var xFaultReason = xFault.Element(nsSoap + "Reason");
untime.Logger.Logger.Error("Web Service call to method '{0}' failed: Code='{1}', Reason='{2}'", methodName, (string)xFaultCode, (string)xFaultReason);
string faultCode = (string)xFaultCode;
var codeParts = faultCode.Split(':');
XmlQualifiedName xmlQualifiedName;
if (codeParts.Length == 2)
{
xmlQualifiedName = new XmlQualifiedName(codeParts[1], codeParts[0]);
}
else
{
xmlQualifiedName = new XmlQualifiedName(faultCode);
}
throw new SoapException((string)xFaultReason, xmlQualifiedName);
}
var xResponse = xReplyBody.Element(this.nsArgs + (methodName + "Response"));
var xResult = xResponse.Element(this.nsArgs + (methodName + "Result"));
if (this.OnTransferring != null)
{
if (!this.OnTransferring())
{
return null;
}
}
var result = new CallResult(xResult);
return result;
}
最佳答案
System.Text.Encoding.UTF8
因为它看起来像 Excel 使用 utf。转换为您喜欢的编码。
关于c# 将包含 HTML 特殊字符的字符串解析为 XElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5460726/
我以一种特殊的方式收到以下错误。 The point at which the driver is attempting to click on the element was not scrolle
我有一些包含如下方法的编译库: public boolean foo(String userID) { Class ntSystemClass = Thread.currentThread()
假设我有下表 name | genre --------------------- book 1 | scifi book 2 | horror book 3
我正在用代码进行语言翻译。 self.title.text = [NSString stringWithFormat:NSLocalizedString(@"Q%ld", nil), (long)qu
我想这样做,但到目前为止,我所拥有的只是: print("Will you go out with me?") 我希望代码能够正常工作,以便人们可以回答“是/否”,如果回答是"is",则将返回一条消息
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How can I decode html characters in c#? 我有来自 HTML 的字符,
我想在 JavaScript 中对以下形式的字符串执行 ucwords(),它应该返回 Test1_Test2_Test3。 我已经在 SO 上找到了一个 ucwords 函数,但它只需要空格作为新词
“任何长度的正数表示为数字字符数组,因此介于‘0’和‘9’之间。我们知道最重要的密码位于数组索引 0 的位置。 例子: - 号码是 10282 - 数组将是数字 = [1,0,2,8,2] 考虑到这一
我目前正在开发一个显示特殊 unicode 字符(例如 ꁴ)的应用 现在我遇到了在旧设备上无法显示这些符号的问题。我如何知道它是否适用于当前设备? 我是否必须为每个 SDK 版本创建一个虚拟 Andr
在 HTML、XML 和部分 DTD 中,有两种特殊的标记结构: 以感叹号开头的标签结束,例如 和 以问号开头的标签 ,例如 和 我的问题是,这些构造类型中的每一种是否都有不同的名称,或者我是否必
我目前正在用 python 构建一个 shell。shell 可以执行 python 文件,但我还需要添加使用 PIPE 的选项(例如“|”表示第一个命令的输出将是第二个命令的输入)。 为了做到这一点
我的 MVC 项目中的路由无法正常工作... 我希望我所有的 View 都在 Views > Shared 文件夹中,如下所示: Error.cshtml (default) Index.cshtml
我有一个函数: public static ImageIcon GetIconImageFromResource(String path){ URL url = ARMMain.class.g
好的,所以我想在我的 html 页面中包含下面的字符。看起来很简单,只是我找不到它们的 HTML 编码。 注意:我想在没有大小元素的情况下执行此操作,纯文本就可以了 ^_^。 干杯。 最佳答案 你可以
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 3 年前。
我是 C# 的新手,正在尝试使用 ASP.Net GridView(框架 3.5),当 gridView 文本包含以下内容时,我发现了一个大问题: ñ/Ñ/á/Á/é/É/í/Í/ó/Ó/ú/Ú or
在 Java 中,我尝试编写一个正则表达式来匹配特殊类型的 HTTP URL: http:///# 所以字符串有 4 段: 字符串文字:“http://”;那么 任意 1 个以上字符的字符串;那么 字
当我写查询时,我在表中有“to”列 SELECT to FROM mytable mysql_error 返回错误,如果将单词to插入``引号,即 SELECT `to` FROM mytable 查
我遇到了一个问题。事实上,我使用越南语文本,我想找到每个包含大写字母(大写字母)的单词。当我使用“re”模块时,我的函数 (temp) 没有捕捉到像“Đà”这样的词。另一种方法 (temp2) 是一次
在我的文本中,我想用一个空格替换以下特殊字符: symbols = ["`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_",
我是一名优秀的程序员,十分优秀!