Editing ODC file in C#

筅森魡賤 提交于 2019-12-25 08:15:24

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5379857/editing-odc-file-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!