Electronic Design

XML Basics For Embedded Apps

The Extended Markup Language consists of just a bunch of tags.

XML, or the Extensible Markup Language, is a standard managed by the World Wide Web Consortium. The flexible text format was initially designed for data exchange on the Internet. Yet it's become much more, despite having simple syntax and semantics (Fig. 1).

With XML, designers can bracket data with a pair of user-defined tags marked by angle brackets. The closing tag text starts with a slash character, and it must match the text in the initial tag. Character case is considered so that doesn't match a closing . Tags can be embedded within other tags to provided a tree-structured hierarchy, with the outermost pair called the root element.

Basically, that's it. The rest of the XML discussion is about details, shortcuts, and syntax. For example, tag names should start with a letter. They can contain numbers but no spaces, and special characters like colons. Of course, names should not start with xml. The actual semantics normally inferred by looking at an XML file like the message in Figure 1 is a matter of interpretation by an application that generates or utilizes the file. For this example, the file could be a message sent via an e-mail package. It could also be a note destined for a database in a personal information manager application.

Tags also may have attributes such as those shown in Figure 2. This is an alternative to using child elements, but there are limitations. For instance, multiple child elements may have the same tag, but only each attribute must be unique within the tag. In general, attributes should hold meta-data or data about the data within an element. Comments such as the one in Figure 3 can provide annotation for people who examine a file. But comments essentially don't exist when the structure of an XML file is defined by the standard while the elements and their contents are not defined.

XML would be useful at this point, but two additional mechanisms describe the contents of a file: an XML Schema and a Document Type Definition (DTD). An embedded application that generates an XML to send would follow the rules set out in one of these schemas, but the application needn't incorporate these directly. Likewise, applications that interpret the file must follow the same rules, but they don't have to utilize the schemas. XML parsers can use the schemas.

This approach is typically used on servers and workstations where space isn't at a premium. Similarly, an XML validator can confirm that a file meets the rules of a schema before an application processes the file. Popular Web browsers like Internet Explorer and Firefox include XML support.

Web browsers can be used to display the contents of an XML file. By itself, though, it looks like the text. Cascading style sheets (CSSs) can be used to reformat the contents of an XML file into an HTML file , which can then be displayed by the Web browser. The preferred way of performing this translation uses another file format called the eXtensible Stylesheet Language (XSL). XSL can also translate an XML to different formats other than HTML for certain embedded applications. But in general, the translation of XML files to different formats tends to be a browser-oriented operation.

One way an embedded device can take advantage of XML-to-HTML transformations is to provide an XML file that references a CSS or, preferably, an XSL file on the workstation or a server. The XML data coming from the embedded device is now much more compact, and the presentation is independent of the device. The XSL file could still be provided by a Web server on the embedded device, although alternative XSL files are usable, too. This approach is an alternative to the current approach of employing a Web server to provide an HTML/browser interface to the device. It works fine for a configuration or status interface, but not so well when it comes to exchanging data with another device. Exchanging data as XML files alone does much better.

XML has made a significant impact on the enterprise and workstation levels. It's used to store configuration data, and even documents. For example, the native storage for the OpenOffice documents and spreadsheets is XML. The Apache build system, ANT, utilizes XML for its build files.

SOAP (simple object access protocol) is one of the first XML-based protocols, but it won't be the last. In fact, many protocols are being used for all sorts of purposes, from controlling business processes to embedded devices. It's definitely time to take note of XML if you aren't already using it.

An XML Binary Characterization is in the works at the World Wide Web Consortium. This would provide an additional, potentially more compact encoding of an XML file. Embedded designers who have projects where space and efficiency are critical might find this of particular interest. Check out the Web site for more details, but don't expect support in the immediate future. Even after approval, time is needed to create the infrastructure to handle it.

World Wide Web Consortium

TAGS: Components
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.