0

I'm reading a book on .NET, and it says "XML can be used to store any type of data including documents (the latest version of Microsoft Office stores documents using XML), pictures, music, binary files, and database information."

Huh? How can those types of data be stored as XML?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
richard
  • 12,263
  • 23
  • 95
  • 151

3 Answers3

2

Office documents are actually ZIP files containing compressed files, mostly in XML. When you have an embedded image, it just stores it in the media subdirectory as a binary file. The XML references it by name, but does not contain a base 64 representation of the contents.

Steven Sudit
  • 19,391
  • 1
  • 51
  • 53
1

In most of the time you just use base64 encoding and then just save this.

In some cases you can of course use a native xml format that does not require encoding. Such as SVG for vector graphics etc.

yankee
  • 38,872
  • 15
  • 103
  • 162
  • Can you elaborate on the using "base64 encoding and then just save this" part? – richard Feb 05 '11 at 08:10
  • You can read about the details of base64 encoding on wikipedia: http://en.wikipedia.org/wiki/Base64 I am not fimiliar with .net unfortunatelly, but I am sure that there is a method in .net that will convert a binary stream or something to a base64 encoded string – yankee Feb 05 '11 at 08:12
  • yankee is correct. One way in .NET is http://msdn.microsoft.com/en-us/library/system.convert.tobase64string.aspx – Steven Sudit Feb 05 '11 at 11:21
1

You can convert them to base64 and store it in xml: Storing base64 data in XML?

Community
  • 1
  • 1
Giorgi
  • 30,270
  • 13
  • 89
  • 125
  • Incredible. What can't we do these days? – richard Feb 05 '11 at 08:11
  • 1
    Right, you *could* do this, but that's not a great idea because Base64 is 33% larger and the conversion itself is slow. It's also not what MS Office actually does. – Steven Sudit Feb 05 '11 at 08:15
  • I'm assuming what you _should_ do is binary serialize? My question was really more academic. I couldn't wrap my mind around how this would happen, but I get it now. Base64 encoding can write out all that data to a character formar that can be stored and decoded later. – richard Feb 05 '11 at 08:17
  • The use of base 64 is relatively advanced: the traditional method would have been base 16, which doubles the size. As for the downvote, it's to alert readers that, while it's possible to do things this way, it's not a good idea. – Steven Sudit Feb 05 '11 at 11:14