Category Archives: Web Development

When to use attributes and when to use elements in XML

So I was wondering today if there is a ruling on when to use attributes in XML. It seems to me it is much easier to parse out data if there are no attributes, but on the other hand I don’t want to put data that isn’t pertinent to the information being held. So my first option was this:

	<address>225 Main Street Nowheresville</address>

My second option was this:

<location id="11">
	<address>225 Main Street Nowheresville</address>

I did some research and found that everyone and their mother was saying, data goes in elements, metadata in attributes. So I did some more research just to make sure I was understanding it completely. I found these two tips to be clearer.

  1. If the information is pertainant to the whole information as a whole, then it is best to make it an element.
  2. Conversely, if the information is used as a reference for other aspects of an application or web site, it is best to set it as an attribute.

Quite possibly the best tips I found were from the X12 Reference Model For XML Design.

  1. “Attributes are atomic and cannot be extended and its existence should serve to remove any and all possible ambiguity of the element it describes. They are ‘adjectives’ to the element ‘noun’.”
  2. “Use elements for data that will be produced or consumed by a business application, and attributes for metadata.”

Further reading: Principles of XML design: When to use elements versus attributes
Elements vs. attributes

MySQL notes

It has been some time since I took my intro to Relational Databases back in the spring of
07. So today I decided to do some research on MySQL and the database in general. So without further adieu, here are some helpful notes.

Data Types

  1. char vs varchar – If a string is inserted of 20 character in length is inserted into a char(30) field, it will take up 30 characters in the database. If that same string 20 characters in length is inserted into a varchar(30) field, it will take up just 20 characters of space.
  2. Int vs smallint – Smallint is used if your number will not exceed the range of -32768 – 32768. Int is used when the number falls between -2147483648 – 2147483648. It is also worthy to mention the other types of integers, tinyint, mediumint, and bigint


Database normalization is quite possibly one of the blurriest areas for me. Going from teachers that profess a web site needs to be normalized to other teachers that say ‘if it works don’t fix it’ I have had to find a middle ground for now until I can make a decision and learn more about it. For most projects I do, I follow through to third normal form (3NF). This prevents from having redundancy, duplicate data, as well as prevents data anomalies from occurring. Data anomalies are incorrect/inconsistent data that is the result of updates or insertions that create “duplicate” records.

On another note, I just purchased a new MySQL book MySQL Crash Course by Ben Forta. It looks to be an excellent replacement for my current book. Just looking through the table of contents and reading a few pages, it covers way more than my previous book I purchased for my relational database class. So stay tuned for MySQL Notes ver.2.

Make all external links open in a new window/tab using jQuery

Alright, so I wanted to make a nice easy way to make all of the external links I post to open in a new tab. It just make sense to not facilitate users leaving your web site.

Step 1)
Target all of the anchor tags on the page when they are clicked.

Alright, so if that worked it means you did something right.

Step 2)
Get the url of the current page and split it down to the base URI for the page.

If that worked you will of course see your domain popup.

Step 3)
Check if the url is your own, if it isn’t add in the attribute of target=”_blank”

		var fullUrl = $(this).attr('href');
		var splitUrl = fullUrl.split("/");
		if((splitUrl[2] != '') && (splitUrl[2] != '')){

If you aren’t familiar with the usage of $(this), it is shorthand for the element clicked on. To finish, obviously replace my domain with your own, and voilĂ .