XML

Although JSON has become perhaps the most common serialization format—in certain circles, anyway—that’s not been wholly at the expense of XML. Many APIs still return it and expect it as input; many applications use it for configuration and storage. At some point, you will definitely need to write XML.

XML as a Tree

XML is fundamentally a representation of a tree. There is a root node, which has children, which may also have children, and so on down a hierarchy of arbitrary depth.

If we represented information about a car, for example, we might end up with XML that looks like this:

 
<car>
 
<make>Ford</make>
 
<model>Model T</model>
 
<engine>
 
<size>2.9 L</size>
 
<power>20 hp</power>
 
</engine>
 
</car>

Our root node is car, representing ...

Get Text Processing with Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.