![](/img/trans.png)
[英]Data at the root level is invalid. Line 1, position 1 on valid in memory xml
[英]data at the root level is invalid. line 1 position 1 in XML
我正在尝试将文档提交到特定服务。 该文档为.doc格式。 我必须将其转换为.pdf,然后为创建的pdf文档创建xml,然后提交XML文档。 这是我的代码:
public string CommitDocumentToRepository(string extension, byte[] fileBytes)
{
//Convert to PDF
byte[] loPDFFileBytes;
ConversionService.ContentResponse loResponse = new DocumentAdapter.ConversionService.ContentResponse();
using (ConversionService.CustomPDFSoapClient loConversionServiceClient = new DocumentAdapter.ConversionService.CustomPDFSoapClient())
{
loResponse = loConversionServiceClient.OfficeToPDFContent(fileBytes, extension);
loPDFFileBytes = loResponse.ContentPDF;
}
if (loPDFFileBytes != null)
{
xform loDocContainer = new xform();
xformInstance loDocProperties = new xformInstance();
loDocProperties.FIRST_NAME= this.FirstName;
loDocProperties.LAST_NAME= this.LastName;
loDocProperties.SEX = this.Sex;
loDocContainer.instance = loDocProperties;
string lsTempFile = System.IO.Path.GetTempFileName();
string lsXMLofProperties = loDocContainer.Serialize();
XmlDocument loDoc = new XmlDocument();
loDoc.LoadXml(lsXMLofProperties);
loDoc.Save(lsTempFile);
byte[] loFilePropertiesXML = Common.StreamFile(lsTempFile);
string lsReturnValue = string.Empty;
try
{
using (ISCommittalService.CommittalSoapClient loCommittalServiceClient = new DocumentAdapter.ISCommittalService.CommittalSoapClient())
{
lsReturnValue = loCommittalServiceClient.CommitDocumentByte(loPDFFileBytes, ".PDF", loFilePropertiesXML);
}
}
catch (Exception loException)
{
ADConnectionException loConnectionException = new ADConnectionException(loException);
throw loException;
}
return lsReturnValue;
}
else
return string.Empty;
}
我收到此错误“服务器无法处理请求。--->根级别的数据无效。第1行,位置1。” 从方法CommitDocumentByte。
这是XML:
<?xml version="1.0" encoding="utf-16"?>
<xform xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<instance>
<FIRST_NAME xsi:type="xsd:string">JOHN</FIRST_NAME>
<LAST_NAME xsi:type="xsd:string">DOE</LAST_NAME>
</instance>
</xform>
我究竟做错了什么? 请指教。
该文档为.doc格式。
DOC文件不是XML。 您不能使用XML解析器解析它们。
DOCX文件是XML(OOXML),但仅在将其从“开放包装约定”包装中提取出来之后。
您要继续发布的XML既不是DOC也不是DOCX。 如果在该文件上出现第1行位置1错误,请首先绝对确保它确实是您要发送到解析器的文件,而不是空的缓冲区/字符串或其他非XML文档。 然后确保正确设置了字符编码。 (您确定它是utf-16而不是utf-8吗?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.