[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Parse binary files into XML, sanitize the XML, reconstitute thebinary

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Tue, 13 Dec 2016 14:19:19 +0000

Parse binary files into XML

Hi Folks,

This is so cool.

Here is a picture of a place in Norway:

That’s a JPEG file. It’s a binary file.

Open it in a hex editor and here’s (a portion of) what you will see:

Fun, aye?

Now, did you know that there is a standard technology for parsing binary files, where the output of parsing is XML? There is, and that technology is called Data Format Description Language (DFDL). It’s awesome.

Using DFDL, I parsed the JPEG (binary) file. That resulted in this XML:

<JPEG>
 
<Segment>
   
<SOI> </SOI>
 
</Segment>
 
<Segment>
   
<APP0>
     
<Length>16</Length>
     
<Identifier>JFIF-APP0</Identifier>
     
<version>
       
<major>1</major>
       
<minor>1</minor>
     
</version>
     
<Units>Dots per inch</Units>
     
<Xdensity>72</Xdensity>
      
<Ydensity>72</Ydensity>
     
<Xthumbnail>0</Xthumbnail>
     
<Ythumbnail>0</Ythumbnail>
     
<RGB/>
   
</APP0>
 
</Segment>
  …
 
</Segment>
 
<Segment>
   
<EOI> </EOI>
 
</Segment>
</JPEG>

 

Wow!

 

Next, I wrote an XSLT program that scoured the XML, removing evil stuff like comments. (Did you know that comments can be inserted into images and you will never see them with your eyes? Yikes!). The output of my XSLT program was a sanitized XML-JPEG file.

 

Lastly, I used DFDL to “unparse” the sanitized XML-JPEG file. DFDL reconstituted the JPEG (binary). Here it is:

That JPEG file doesn’t have any evil stuff in it. (Well, lesser amounts of evil stuff anyway)

Let’s recap: using a standard technology (DFDL) I parsed a binary file (JPEG). The output is XML. I then processed the XML using the full suite of XML technologies (XSLT, Schematron, XML Schema, etc.). Lastly, I unparsed the XML to reconstitute the binary.

That is totally amazing!

/Roger

 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.