读取xml节点InnerText为pdf或jpg或png或word文档 [英] read xml nodes InnerText As pdf or jpg or png or word document

查看:82
本文介绍了读取xml节点InnerText为pdf或jpg或png或word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我想在XML节点的InnerText中嵌入和检索pdf,word doc,jpg或png图像等文件.
如何将文件更改为String以插入xml节点?
请帮助我

Hello
I want to embed and retrive files such as pdf, word doc, jpg or png images In InnerText of XML nodes.
How can I change my files to String to insert into xml nodes?
please help me

推荐答案

有两种可能:
There are two possibilities:

  1. 将文件转换为十六进制编码的字节字符串,并使用它
  2. 将文件位置作为字符串(可能作为CDATA项目

  1. Convert your file into a hexadecimal encoded byte string, and use that
  2. Insert the file location as a string possibly as a CDATA item


)插入 选项2更合适,因为它将减少XML中的数据量.但是,可能XML不是解决您问题的最佳解决方案.


Option 2 would be more appropriate as it would reduce the amount of data in the XML. However, it may be that XML is not the best solution to your problem.


如果您的目的是将多个文件保存在一起,以便轻松移动或访问相关文件,那么我个人会使用zip.如果有任何疑问,请参阅这篇文章
C#压缩文件和/或文件夹 [
if your purpose is to save multiple files together, making it easy to move or access related files, then I personally would use zip. If this has any interrest have a look at this article
C# Zip Files and/or Folders[^]


最好的方法是读取文件的所有字节并进行转换按字节排列的数组到Base64,并将结果文本插入innertext.

byte [] bytes = System.IO.File.ReadAllBytes(filename);
字符串str = Convert.ToBase64String(bytes);
the best way is read all bytes of file and convert that array of byts to Base64 and insert result text into innertext.

byte[] bytes = System.IO.File.ReadAllBytes(filename);
String str = Convert.ToBase64String(bytes);


这篇关于读取xml节点InnerText为pdf或jpg或png或word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆