From the course: Exploring C Libraries

Understanding XML - C Tutorial

From the course: Exploring C Libraries

Start my 1-month free trial

Understanding XML

- [Narrator] The C language has primitive data types, which are useful, but not up to speed with the complex data interchange formats used by more recent languages such as Javascript and Python. One of the most widely used data interchange formats is XML. XML data is stored as plain text. And this data can be accessed or created by linking in an XML library to your C code. XML is the Extensible Markup Language. It's a cousin to HTML, the formatting language used on the World Wide Web. XML is used to describe, store, and transport data. To describe data, XML uses tags. A tag is enclosed in angle brackets. One tag marks the start of a chunk of data, and it consists of a case-sensitive word. A closing tag marks the end of the data chunk, containing the same word, but prefixed by a slash (/). A single tag can also be used, though tag pairs are more common. Tags are user defined. You can use whatever tags you need, descriptive tags are best. The first line XML data is often a special tag called a prolog. The prolog defines the XML version, and character encoding. Here's a typical XML prolog tag, the tag lacks a closing tag. The next tag in the XML document is the root tag. Within the root tag are various child tags, and even sub-child tags. All these tags match up with closing tags. Tags also contain attributes, which are further descriptive elements. The attribute features a name, followed by an equal sign (=), and then a value enclosed in double or single quotes. No further rules describe how this data is configured. The decision is up to whoever creates the XML data. For the C language, a host of XML libraries are available. One I've used is libxml2, which is available from the website xmlsoft.org, shown here. If you're using a package manager, you can search for and install the libxml2-dev library. You can also opt to manually install the library, which is compatible with Code::Blocks in Windows. Documentation and sample code are available on the xmlsoft website.

Contents