Relfor

Why jQuery is called jQuery, a brief look back at XML parsing

I would assume that quite a lot of developers out there already know the origins of its name, however for those who don't and want a detailed story about; they can continue reading :)

XML, unorganized data before JSON

JSON is a relatively new way of storing information in a quick & I would say unorganized fashion. Before JSON we had something known as XML which ruled the world of data storing in this domain.

Sample XML:

<? xml version="1.0" ?>
<Customers>
    <Customer id="4510">
        <Name>John Smith</Name>
        <Age>31</Age>
    </Customer>
    <Customer id="9105">
        <Name>Rebecca Olsen</Name>
        <Age>27</Age>
    </Customer>
</Customers>

Let us say that your application stored customers in the format as given above. The above dataset is rather simple, in reality it can get much more complex than this.

xPath
To query xml data like the one given above there is a tool named xPath. To select the name of the customer whose customer ID is 4510 the xPath query would be:

/Customer[id="4510"]/Name

If you replace the '/' with '>' and '//' with ' ' xPath begins to look very much like CSS Selectors. jQuery queries are designed to mimic CSS Selectors. jQuery query selectors is of a separately maintained project known as Sizzle.js

xQuery
The querying functionality provided by xPath is powerful. Many programming languages out there have libraries which will perform xPath for you on XML data, giving you the ability to store xPath results in variables and use it with the logic of the programming language being used. There is a separate functional programming language dedicated to XML parsing and creation which has xPath at its heart.

In the above example to create an XML document with xQuery one would do something like:

$Customers = doc('Customers.xml') (: assuming  that the xml document is stored in the same folder as a file 'Customers.xml' :)
$specificCustomer = Customers/Customer[id="4510"]/Name
return {
    <Customer>
        <Name>$specificCustomer</Name>
    </Customer>
}

Getting to the naming

You might be thinking:

Sizzle is (kind of) to JSON, as xPath is to XML.
jQuery is (kind of) to JSON, as xQuery is to XML.

It goes without saying that jQuery isn't exactly to JSON as xQuery is XML. xQuery is a full blown turing complete functional programming language, whereas jQuery is merely a ~60kb library written in JavaScript itself. Finally, John Resig chose to name jQuery jQuery, to me this was a decent choice for a name.

Comments Section

    Leave a Comment