[英]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.