简体   繁体   中英

data at the root level is invalid. line 1 position 1 in XML

I'm trying to commit a document to a specific service. The document is in .doc format. I have to convert it to .pdf then create an xml to the created pdf document then commit the XML document. This is my code:

 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;


    }

I'm getting this error "server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1." from the method CommitDocumentByte.

This is the 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>

What am I doing wrong? Please advise.

The document is in .doc format.

DOC files are not XML; you cannot parse them with an XML parser.

DOCX files are XML (OOXML), but only after extracting them from their Open Packaging Convention wrapping.

The XML you go on to post is neither DOC nor DOCX. If you're getting a line 1 position 1 error on that file, first make absolutely sure that it is indeed that file that you're sending to the parser and not an empty buffer/string or some other non-XML document. Then make sure that you have the character encoding set properly. (Are you sure it's utf-16 and not utf-8?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM