Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Getting System.Xml.XmlException:名称不能以'';字符,十六进制值0x20。第42行,第36位_C#_Asp.net - Fatal编程技术网

C# Getting System.Xml.XmlException:名称不能以'';字符,十六进制值0x20。第42行,第36位

C# Getting System.Xml.XmlException:名称不能以'';字符,十六进制值0x20。第42行,第36位,c#,asp.net,C#,Asp.net,我得到了这个错误,到目前为止我所发现的只是“删除空间”,但是没有空间。这是我发现的一个脚本,它可以从任何文件格式中提取简历数据(解析数据),然后将其放入SQL数据库中……还没到那个地步 ASP.net代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ResumeParser.aspx.cs" Inherits="CsharpSamCodeResumeParser_USAResume" Debug="true"

我得到了这个错误,到目前为止我所发现的只是“删除空间”,但是没有空间。这是我发现的一个脚本,它可以从任何文件格式中提取简历数据(解析数据),然后将其放入SQL数据库中……还没到那个地步

ASP.net代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ResumeParser.aspx.cs"       Inherits="CsharpSamCodeResumeParser_USAResume" Debug="true" ValidateRequest="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
    <table style="width: 574px; height: 95px">
        <tr>
            <td style="width: 507px">
                Resume
                URL</td>
            <td style="width: 737px">
                <asp:TextBox ID="TxtUrl" runat="server" Width="424px"></asp:TextBox>
            </td>
        </tr>            
        <tr>
           <td colspan="2" align="center">                  
                    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Resume parser" /></td>
            </tr>
        </table>

    <table>
        <tr>
            <td style="width: 247px; height: 287px">
                PARSING RESULTS</td>
            <td style="width: 568px; height: 287px">
                <asp:TextBox ID="TxtOutput" runat="server" Height="276px" TextMode="MultiLine" Width="565px"></asp:TextBox></td>
        </tr>
    </table>

</div>
</form>

无标题页
简历
统一资源定位地址
解析结果

C#:

public分部类csharpsamcodereumparser\u USAResume:System.Web.UI.Page
{
//////////配置设置////
string ServiceUrl=(string)ConfigurationSettings.AppSettings[“webServiceUrl”];
受保护的无效页面加载(对象发送方、事件参数e)
{
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
///////////////////可变启动///////////////
字符串url=TxtUrl.Text;
StringBuilder strRequest=新建StringBuilder();
string userkey=(string)ConfigurationSettings.AppSettings[“userkey”];
字符串版本=(字符串)配置设置。应用设置[“版本”];
字符串countryKey=(字符串)ConfigurationSettings.AppSettings[“countryKey”];
/////////////////可变端///////////////////
请求。追加(“”);
请求。追加(“”);
请求。追加(“”);
请求。追加(“”);
追加(“+url+”);
追加(“+userkey+”);
追加(“+version+”);
追加(“+countryKey+”);
请求。追加(“”);
请求。追加(“”);
请求。追加(“”);
///////////////soapxml端///////////////////
/////////////////XML处理//////////////////////
byte[]byteArray=Encoding.ASCII.GetBytes(strRequest.ToString());
HttpWebRequest httpRequest=(HttpWebRequest)WebRequest.Create(ServiceUrl);
httpRequest.Credentials=CredentialCache.DefaultCredentials;
httpRequest.Method=“POST”;
httpRequest.ContentType=“text/xml”;
httpRequest.ContentLength=byteArray.Length;
Stream dataStream=httpRequest.GetRequestStream();
写入(byteArray,0,byteArray.Length);
dataStream.Close();
/////////////////////过程结束////////////////
//////////////////收到的答复///////////////////////
HttpWebResponse httpResponse=(HttpWebResponse)httpRequest.GetResponse();
StreamReader StreamReader=新的StreamReader(httpResponse.GetResponseStream(),System.Text.Encoding.UTF8);
string ack=string.Empty;
//ack=streamReader.ReadToEnd().ToString();
////////////////////从响应XML获取节点值/////////////
使用(XmlReader=XmlReader.Create(streamReader))
{
while(reader.Read())
{
if(reader.NodeType==XmlNodeType.Element)
{

对于(int count=1;count,您在这里有相互矛盾的陈述:

strRequest.Append("<?xml version='1.0' encoding='utf-8'?>");
你可能会把编码搞得一团糟,最终会得到不需要的字符


您应该将
Encoding.ASCII
替换为
Encoding.UTF8

我怀疑,因为您是通过字符串连接创建xml文档的,所以无意中添加了来自某个变量的格式错误的xml。可能其中一个变量的符号小于,这导致xml解析器爆炸。您应该尝试创建通过一个DOM调用文档,或者可能使用可配置值的部分

string url = TxtUrl.Text;        
string userkey = (string)ConfigurationSettings.AppSettings["userKey"];
string version = (string)ConfigurationSettings.AppSettings["Version"];
string countryKey=(string)ConfigurationSettings.AppSettings["CountryKey"];    

strRequest.Append("<url>" + url + "</url>");
strRequest.Append("<key>" + userkey + "</key>");
strRequest.Append("<version>" + version + "</version>");
strRequest.Append("<countryKey>" + countryKey + "</countryKey>");
stringurl=TxtUrl.Text;
string userkey=(string)ConfigurationSettings.AppSettings[“userkey”];
字符串版本=(字符串)配置设置。应用设置[“版本”];
字符串countryKey=(字符串)ConfigurationSettings.AppSettings[“countryKey”];
追加(“+url+”);
追加(“+userkey+”);
追加(“+version+”);
追加(“+countryKey+”);

我会尝试将
strRequest
StringBuilder写入一个文件,然后在xml编辑器中打开它,并找出问题所在。

您检查过输入变量吗?可能需要对它们进行修剪和URL编码……我很傻,谢谢您的帮助(代码离线,需要输入一些空格)谢谢你的帮助
byte[] byteArray = Encoding.ASCII.GetBytes(strRequest.ToString());
string url = TxtUrl.Text;        
string userkey = (string)ConfigurationSettings.AppSettings["userKey"];
string version = (string)ConfigurationSettings.AppSettings["Version"];
string countryKey=(string)ConfigurationSettings.AppSettings["CountryKey"];    

strRequest.Append("<url>" + url + "</url>");
strRequest.Append("<key>" + userkey + "</key>");
strRequest.Append("<version>" + version + "</version>");
strRequest.Append("<countryKey>" + countryKey + "</countryKey>");