Include binary data in XML file

吃可爱长大的小学妹 提交于 2019-12-10 10:14:59

问题


We need to upload the attachments(for ex. word document) in xml file. Is there any way to attach this? Any sample code using c# will be appreciated.


回答1:


Have a look at this article: http://www.codeproject.com/KB/XML/xml_serializationasp.aspx it describes saving bmp images into and out of xml by converting them to byte arrays. I suspect a similar method would work for other files.




回答2:


An alternative is to store a uri to the resource instead of attempting to include it within the XML.

<?xml version="1.0"?>
<item>
    <attachment type="word">http://path.to/document</attachment>
</item>

The client is going to have to do some work to either unencode or fetch the attachment anyway so doing it this way could save a lot of pain.



来源:https://stackoverflow.com/questions/4522119/include-binary-data-in-xml-file

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