简体   繁体   中英

Editing ODC file in C#

I am trying to edit an .odc file in c# i thought it would be simple because its just xml but when i run it and it comes to Load the document xmlDoc.Load("THEFILE.odc") it gives me an error:

'Content-Type' is an unexpected token. The expected token is '"' or '''. Line 5, position 18. And that is i figure talking about Line 5 position 18 of the doc itself which is:

<meta http-equiv=Content-Type content="text/x-ms-odc; charset=utf-8">

the file is below. it is an odc file. I need to go through the connection properties and change the ConnectionString. Thanks in advace

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/x-ms-odc; charset=utf-8">
<meta name=ProgId content=ODC.Table>
<meta name=SourceType content=OLEDB>
<title>Title</title>
<xml id=docprops><o:DocumentProperties
  xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns="http://www.w3.org/TR/REC-html40">
  <odc:Connection odc:Type="OLEDB">
   <odc:ConnectionString>"ConnectionString"</odc:ConnectionString>
   <odc:CommandType>Table</odc:CommandType>
   <odc:CommandText>"CommandText"</odc:CommandText>
   <odc:SSOApplicationID>testReport</odc:SSOApplicationID>
   <odc:CredentialsMethod>Stored</odc:CredentialsMethod>
  </odc:Connection>
 </odc:OfficeDataConnection>
</xml>
<style>
<!--
    .ODCDataSource
    {
    behavior: url(dataconn.htc);
    }
-->
</style>

</head>

Theres more to the file itself but above is the xml which im trying to edit.

Thanks

Your .ODC file looks like XML but it's not. It doesn't respect some XML rules. For instance the meta tags are not closed.

<meta name=ProgId content=ODC.Table>

should be

<meta name="ProgId" content="ODC.Table"/> (notice the quotes and slash added)

And for the first error for Content-Type; it should be :

<meta http-equiv="Content-Type" content="text/x-ms-odc; charset=utf-8"/> (Content-Type need to be surrounded with quotes (or single quotes)).

I'd suggest you to load directly your .ODC file with HTML Agility Pack or use some cleansing tool before loading it.

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