c# - C# 中的 XML 文档 (0, 0) 有错误
问题描述
我有源代码:
string epcisSettings = ConfigurationManager.AppSettings["EPCISSettings"];
if (!epcisSettings.EndsWith(@"\"))
{
epcisSettings += @"\";
}
string filePath = epcisSettings + ((BizStepCode)bizStepItems.BizStepCode).ToString().ToUpper() + ".xml";
File.WriteAllText(filePath, "");
LogWriter.LogOutput(LogType.INFO, "DAOEpcRecords.addEpcRecords", "EPCISSettingsFilePath = " + filePath);
LocationMasterRecords locationMasterRecords = new DAOLocationMasterRecords(this.connectionString).getLocationMasterRecords();
LocationMasterRecords.LocationMasterItems locationMasterItems = locationMasterRecords.LocationMasterList.Where(q => q.LocationCode == bizStepItems.LocationCode).First();
using (StreamReader reader = new StreamReader(filePath))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ObjectEventType));
ObjectEventType objectEventType = new ObjectEventType();
objectEventType = (ObjectEventType)xmlSerializer.Deserialize(reader);
objectEventType.epcList = epcList.ToArray();
objectEventType.eventTime = DateTime.Now;
objectEventType.eventTimeZoneOffset = DateTime.Now.ToString("zzz");
ReadPointType readPointType = new ReadPointType();
readPointType.id = "1";
objectEventType.readPoint = readPointType;
BusinessLocationType businessLocationType = new BusinessLocationType();
businessLocationType.id = "12";
objectEventType.bizLocation = businessLocationType;
EPCISDocumentType epcisDoc = new EPCISDocumentType();
epcisDoc.EPCISBody = new EPCISBodyType();
epcisDoc.EPCISBody.EventList = new object[1];
epcisDoc.EPCISBody.EventList[0] = objectEventType;
byte[] bsRequest = EpcSerializer.ToEPCISDocumentTypeBytes(epcisDoc);
HttpCli client = new HttpCli();
client.Open(Properties.Settings.Default.CoreCaptureServiceURI);
client.DoPost(bsRequest, "text/xml; charset=utf-8", null, 60000);
if (client.StatusCode != HttpStatusCode.OK)
{
throw new Exception("HTTP " + client.StatusCode + " ");
}
}
这是类错误:objectEventType = (ObjectEventType)xmlSerializer.Deserialize(reader);
XML 文档 (0, 0) 中存在错误。我尝试了很多方法,但它没有运行。下面是我的 xml 文件,我在许多不同的论坛上找到了答案,但是当放入代码时它不起作用。
<epcis:EPCISDocument xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:cbvmda="urn:epcglobal:cbv:mda">
<EPCISBody>
<EventList>
<ObjectEventType>
<eventTime>2018-04-10T15:00:02.449Z</eventTime>
<eventTimeZoneOffset>+09:00</eventTimeZoneOffset>
<epcList>
<epc>urn:epc:id:giai:1234567.1111</epc>
<epc>urn:epc:id:giai:1234567.222</epc>
<epc>urn:epc:id:giai:1234567.33</epc>
</epcList>
<bizStep>urn:epcglobal:cbv:bizstep:commissioning</bizStep>
<disposition>urn:epcglobal:cbv:disp:active</disposition>
<readPoint>
<id>urn:epc:id:sgln:0400001.00300.0</id>
</readPoint>
<bizLocation>
<id>urn:epc:id:sgln:04000001.00300.0</id>
</bizLocation>
<extension>
<ilmd>
<cbvmda:itemExpirationDate>2015-03-15</example:expiry>
<cbvmda:lot>A123</example:lot>
</ilmd>
</extension>
</ObjectEventType>
</EventList>
</EPCISBody>
</epcis:EPCISDocument>
解决方案
推荐阅读
- node.js - 仅使用 DynamoDB 中的分区键进行查询
- sql - 将数据从一个表复制到另一个表 - 忽略重复 Postgresql
- batch-file - 如何替换父批处理文件?
- html - 如何为响应式网页设计设置最小宽度,然后让设备缩放以适应该点以下?
- postgresql - postresql group by 查询耗时太长
- angular - “块”参数必须是字符串或缓冲区类型之一。接收到的类型对象
- c# - 获取从社交登录提供商返回的流量,以在我的 .net core 2.2 Web 应用程序上创建本地帐户
- java - 在分布式环境中使用没有 EJB 的 JPA
- swift - 如何同时从firebase获取数据的第一级和第二级数据?
- c++ - 可以返回兄弟对象的函数的自动返回类型