Archive

Posts Tagged ‘xml’

The Angle Bracket Tax

September 8, 2014 8 comments

The following C++14 code fragment represents a general message layout along with a specific instantiation of that message:

Message Code Frag

 

Side note: Why won’t a C++98/03 compiler accept the above code?

Assume that we are “required” to send thousands of these X-Y position messages per second between two computers over a finite bandwidth communication link:

Sensor To Display

There are many ways we can convert the representation of the message in memory into a serial stream of bytes for transmittal over the communication link, but let’s compare a simple binary representation against an XML equivalent:

XML Vs Binary

The tradeoff is simple: human readability for performance. Even though the XML version is self-describing and readable to a human being, it is 6.5 times larger than the tight, fixed-size, binary format. In addition, the source code required to serialize/deserialize (i.e. marshal/unmarshal) the XML version is computationally denser than the code to implement the same functionality for the fixed-size, binary representation. In the software industry, this tradeoff is affectionately known as “the angle bracket tax” that must be payed for using XML in the critical paths of your system.

If your system requires high rates of throughput and low end-to-end latency for streaming data over a network, you may have no choice but to use a binary format to send/receive messages. After all, what good is it to have human readable messages if the system doesn’t work due to overflowing queues and lost messages?

XML In UML

October 13, 2010 Leave a comment

While learning XML, I concocted this UML class diagram of the conceptual structure of XML as a quick look refresher guide:

The diagram can be interpreted as:

  • A typical XML document is composed of  a “Document Element“, an optional “Prolog Element”, and many application specific “Element” classes.
  • Besides a base “Element” class, there are two subclass types: the “Document Element” and the “Prolog Element”.
  • In an XML file, the “Prolog Element” (if present) must precede the “Document Element”.
  • An element contains content and, optionally, 1 or more “Attributes”.
  • Each “Attribute” is comprised of a Name/Value pair.
  • An element can also contain other nested elements, providing support for structured data representation.

Here’s a simple concrete example XML file and the mapping from concrete to abstract. Note that the “comment” and “xml declaration” lines aren’t represented in the abstract class diagram model. I left out that second order level of detail to keep the class diagram simple.

%d bloggers like this: