5 Common XML Errors

XML document code
kr7ysztof/Getty Images

The XML (Extensible Markup Language) language is so simple that just about anyone can master it. That kind of accessibility is a key benefit of the language. The drawback to XML is that the rules that do exist in the language are absolute. XML parsers leave little room for error. Whether you are new to ​XML or have been working in the language for years, the same common errors tend to pop up over and over again. Let's take a look at five common mistakes people make when authoring documents in XML so that you can learn to avoid these missteps in your own work.

of 05

Forgetten Declaration Statement

Despite all their technical complexities, computers cannot yet think for themselves and use intuition to figure out what a statement means in different instances. You need to specify the language with a declaration statement so that the browser understands the code that you will write. Forget this statement and the browser will have no idea which language you are using and will, therefore, be unable to do much with the code that you write.

of 05

Unnested Elements or Text

XML works in a hierarchical style. This means:

  • All child elements must have parents.
  • All data strings must be between element tags.
  • All comments must be inside comment tags.
of 05

Open Tags

XML requires you to close all of the tags that you open. In HTML, you can get away with the occasional open tag, and some browsers will even close tags for you when they render a page. The document might still parse even if not well-formed. XML is much fussier than that. An XML document with an open tag will produce an error at some point.

of 05

No Root Element

Since XML works in a tree-structure, every XML page must have a root element at the apex of the tree. The name of the element is not important, but it must be there or the tags that follow will not be properly nested.

of 05

Multiple White-Space Characters

XML interprets 50 blank spaces the same as it does one.

XML Code:
                Hello World!

Hello World!

XML will take multiple blank spaces, known as white-space characters, and compact them into one space. Remember, XML is about carrying the data. It is not about the presentation of that data. It has nothing to do with visual display or design. A white space used to align text means nothing in XML code, so if you are adding lots of extra spaces to try to dictate some kind of visual layout or design, you are wasting your time.

Edited by Jeremy Girard