Skip to content Skip to navigation

OpenStax-CNX

You are here: Home » Content » XML Basics

Navigation

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

XML Basics

Module by: Sarah Coppin, Bill Wilson. E-mail the authors

Summary: Explains what XML (eXtensible Markup Language) is and the rules that govern its usage.

Note: You are viewing an old version of this document. The latest version is available here.

What is XML?

XML is a markup language to write markup languages in. A markup language is any language (HTML, for example) that uses tags surrounding text to convey information such as content or format. CNXML is a language written in XML. Here is an example:

                  
	<para>
	This is a paragraph in CNXML.
	</para>
      
                

<para> and </para> are the tags that the enclose the text, "This is a paragraph in CNXML."

XML allows the separation of presentation from content. HTML tends to have tags such as <b> and <i>, which bold and italicize things respectively. However, if you made every title of a book underlined and then wanted to change it to italics, you would have to manually change each underline tag to an <i>. However, in XML you can make a tag called <title> and create a stylesheet, which is a separate document, that says that every <title> tag should be italicized or underlined. Then when you want to change the presentation of that type of content, you just change one small part of the stylesheet and consequently every file that uses that stylesheet. Also, if you make tags that convey the content of the document, you can enable better searching. For example, you might look for the author of a document by looking at the author tag.

XML Rules

XML has three rules that apply to all of its languages, including CNXML.

  • Every tag that is opened must be closed. An opening tag looks like <module> and a closing tag looks like </module>. There is a shortcut. If your tag contains no other tags (referred to as an empty tag), then you can can type a / before the end of the opening tag and delete the closing tag. For example, <mediaobject> </mediaobject> can be abbreviated <mediaobject/>
  • Tags must be nested within each other. So, <b>red <i>and</i> blue</b> is fine, but <b>red <i>and</b> blue</i> is incorrect because the <b> and <i> tags have overlapping content.
  • You must put either single or double quotes around an attribute value. For example, <module id="m0001"> and <module id='m0001'> are fine, but <module id=m0001> is incorrect.

Resources

The World Wide Web Consortium(W3C) is responsible for XML.

Content actions

Download module as:

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks