Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How important is it to learn XML when JSON is able to do almost all that I need? Having said that, I use JSON mainly for AJAX requests and obtaining data from various APIs. I am a total newbie to web development and the reason I am asking this is that I want to know whether I should go ahead and buy a book on XML or whether I can just give it a pass.

share|improve this question
2  
Given that you'll encounter XML on a rather consistent basis, I'd go ahead and get the book. –  Tim Post Nov 11 '10 at 7:59
10  
Just read the standard. I've never found XML challenging to learn/understand, just tedious. –  dietbuddha Nov 12 '10 at 9:54
    
I never understood that either- what is so difficult about understanding XML? 99.9% of XML out there is just used as a container for data- it's simple text files people, not anything complicated! –  Keith Palmer Apr 16 '12 at 18:25
    
everyone should us CSV... –  jonathan Apr 16 '12 at 19:25
1  
@KeithPalmer: and still there is a high amount of mistakes to be found all around the web. From wrong encoding declaration, to missing escapes for characters that need them to simply using a XML file as one huger CDATA container. And don't get me started about how to misues namespaces. –  Joachim Sauer Nov 12 '12 at 9:26
add comment

2 Answers

up vote 25 down vote accepted

You'll need to learn XML to get anywhere in the web world. It's what drives of lot of B2B communications and there are many standard XML formats describing important.

Just restricting yourself to JSON is hugely self-limiting. Yeah, you'll be chucking AJAX calls around but what happens when you need to communicate with a GeoServer? It'll be adhering to GIS standards and will be spurting out XML in WCS (Web Capabilities Service), WMS (Web Map Service) and WFS (Web Feature Service) formats among others. If you don't know how to handle XML, you'll have some trouble with that.

Of course, any marshaller (domain object to text format) worth its salt will be able to convert their objects to and from XML/JSON/YAML so you could make the argument that so long as you can hide behind the marshaller you only have to deal with the domain objects. Web services provide WSDL exactly for this purpose. But sooner or later you'll need to read and understand the contents of your requests and responses and that will certainly require an understanding of XML.

And let's not forget good ol' XHTML the old web standard for HTML pages. It's XML.

So, in short, learn XML - and keep JSON wherever you can 'cos it's lovely.

share|improve this answer
1  
Thanks a lot Gary!XML looks so bloated and really scary to dive in though, but going by what you said, seems like I will have to learn it......! –  Rasmus Nov 11 '10 at 10:37
    
@Alice Start off slow. Think of it as repetitive HTML. Then allow for case sensitivity. Then consider how different data types (e.g. int, string, date) could be represented and tagged inside those elements or attributes. Then make that data type representation a bit more formal (XSD) and you're about as far as you'll need to go. This tutorial should help: devguru.com/features/tutorials/xml/beginning_xml.html –  Gary Rowe Nov 11 '10 at 10:52
1  
I don't know what language / framework / platform you use, but whichever it is, I'm sure you'll find that it has standard libraries for parsing and generating XML, you shouldn't find yourself interpreting pointy brackets manually. –  Carson63000 Nov 12 '10 at 0:56
5  
+1, though for what it's worth, XHTML isn't really all that new and seems to have moved to the backseat with HTML 5. –  John M Gant Dec 29 '10 at 20:53
1  
Maybe. My point was more that the W3C seems like their thinking on XHTML has changed a little in the past few years. It's still there and supported, but it's no longer like you're some kind of IE-loving table-layout-using script kiddie if you use plain HTML instead of XML. It's kinda tangential to your answer anyway though, sorry about that. –  John M Gant Dec 29 '10 at 21:09
show 1 more comment

XML definitely outshines JSON for markup (which is, after all, hinted at in the name).

I wouldn't like to see a random XHTML page converted into JSON format. It would be horrible. OpenOffice and the latest editions of Microsoft Office all use compressed XML as their format of choice.

As a general rule: Markup goes in XML; structured data goes in JSON.

That's when you're outputting data and have full control yourself over the format. If you're outputting data according to industry standards, or consuming other people's data, you may need to use XML even in places where JSON would seem more appropriate. That's because XML is longer established and has been used in many standards.

share|improve this answer
    
+1, especially for noting the difference between markup and structured data. –  MainMa Feb 15 '13 at 13:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.