Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML

Can someone give an explanation of what XML is?

I have been reading about it a lot and have scanned a few very technical documents that don't really clarify what it is. My sub questions would be: Why is it relevant? How is it used on the web and in other programs?

1 Answer

Steven Parker
Steven Parker
243,134 Points

XML stands for eXtensible Markup Language

It basically defines the "pattern" that HTML is based on, where things are identified using tags, and tags can be nested, and tags can have attributes.

XML is more generic than HTML, where the tags in HTML come from a defined set, and each tag has a particular meaning to the document. But in XML the tags and attributes can be anything.

It's used in web and other applications primarily as a way to store and transmit data. It has an advantage over other data formats in that it can be read by humans and edited with ordinary text editors.

Here's an example of XML (but this is not valid HTML):

<food>
    <fruit name="banana">
        <color>Yellow</color>
        <shape>Long</shape>
        <taste>Sweet</taste>
    </fruit>
    <fruit name="orange">
        <color>Orange</color>
        <shape>Round</shape>
    </fruit>
    <nut name="almond">
        <color>Brown</color>
    <nut>
</food>

Thanks for your reply.

What I don't get is if it is a readable format how is it used to transmit data. As in how is data converted into XML format? I have heard that JSON is being used as a more popular alternative. How do they differ and why is this the case if XML is so readable?

Steven Parker
Steven Parker
243,134 Points

Just like there are software libraries for converting to and from JSON, there are libraries for converting to and from XML. JSON is another human-readable format that organizes data in key/value pairs. It is a newer format and has been used as a replacement for XML for some applications.