我正在尝试将文档提交给特定服务。该文档采用.doc格式。我必须将其转换为.pdf,然后创建一个xml到创建的pdf文档,然后提交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>
我做错了什么?请指教。
答案 0 :(得分:0)
该文件采用.doc格式。
DOC文件不是XML;你无法用XML解析器解析它们。
DOCX文件是XML(OOXML),但只有在从Open Packaging Convention包装中提取后才能使用。
您发布的XML既不是DOC也不是DOCX。如果您在该文件上遇到第1行1位错误,请首先确保它确实是您发送给解析器的文件,而不是空缓冲区/字符串或其他非XML文档。然后确保正确设置了字符编码。 (你确定它是utf-16而不是utf-8吗?)