本文介绍了Xml列出代码时出错.名称中不能包含':'字符,十六进制值0x3A的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的xml的摘录,
This is a snippet of my xml,
<e80:td941Grp>
<e80:td941KeyGrp>
<e80:membExchIdCod>XX445678</e80:membExchIdCod>
<e80:membExchIdNam>XX44567899123</e80:membExchIdNam>
</e80:td941KeyGrp>
<e80:td941Rec>
<e80:prodId>5AB</e80:prodId>
<e80:quoReqTot>0</e80:quoReqTot>
<e80:dCutLim>150</e80:dCutLim>
<e80:goodQuoReqResp>0</e80:goodQuoReqResp>
<e80:quoReqViol>0</e80:quoReqViol>
<e80:shtQuoPct>0.00</e80:shtQuoPct>
<e80:valQuoReqViol>0</e80:valQuoReqViol>
<e80:valQuoReqTot>0</e80:valQuoReqTot>
<e80:valGoodQuoReqResp>0</e80:valGoodQuoReqResp>
<e80:violPct>0.00</e80:violPct>
</e80:td941Rec>
这是我的代码,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Serialization;
namespace WindowsFormsApplication1
{
public class td941Rec
{
private string _prodID;
private string _qouReqTot;
private string _dCutLim;
private string _goodQuoRepResp;
private string _quoReqViol;
private string _shtQuoPct;
private string _valQuoReqViol;
private string _ValQuoRepTot;
private string _valGoodQuoReqResp;
private string _violPct;
public string prodID { get; set; }
public string qouReqTot { get; set; }
public string dCutLim { get; set; }
public string goodQuoRepResp { get; set; }
public string quoReqViol { get; set; }
public string shtQuoPct { get; set; }
public string valQuoReqViol { get; set; }
public string ValQuoRepTot { get; set; }
public string valGoodQuoReqResp { get; set; }
public string violPct { get; set; }
}
public class td941Grp
{
private string _td941;
public string td941 { get { return _td941; } set { _td941 = value; } }
public List<td941Rec> dataList = new List<td941Rec>();
}
class QoutePerformance
{
public void xmltoExcel()
{
string xmlDoc = @"........xxxxx.xml";
XDocument xdoc1 = XDocument.Load(xmlDoc);
td941Grp objtd941 = new td941Grp();
List<td941Grp> listtd941 = (from _td941 in xdoc1.Element("e80:td941")
.Elements("e80:td941Grp")
select new td941Grp
{
td941 = _td941.Element("e80:td941Grp").Value,dataList = (from _record in _td941.
Element("e80:td941Grp").Elements("e80:td941Rec")
select new td941Rec
{
prodID = _td941.Element("prodID").Value,
qouReqTot = _td941.Element("qouReqTot").Value,
}).ToList()
}).ToList();
}
我收到未处理的XmlException错误名称中不能包含':'字符,十六进制值0x3A."
I get the error XmlException was unhandled "The ':' character, hexadecimal value 0x3A, cannot be included in a name."
相对于C#而言,我相对较新,但是xml的新手,因此在此提供的任何帮助将不胜感激.
Im relatively newb to c# but an total novice at xml so any help here would be greatly appreciated.
谢谢
推荐答案
您不能使用.Element("e80:td941")
相反,请使用XNamespace:
Instead, use an XNamespace:
XNamespace nsE80 = xmlDoc.GetNamespaceOfPrefix("e80");
... .Element(nsE80 + "td941")
这篇关于Xml列出代码时出错.名称中不能包含':'字符,十六进制值0x3A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!