Archive for May, 2007

Easy XML with Java - XML Binding

Thursday, May 17th, 2007

Recently in a Java project that I’m currently working on it was necessary to read remote XML data. Since my Java skills aren’t too strong and that I’ve never used Java and XML together I hit the road to search for help. I quickly found some articles and tutorials about dealing with XML within Java. I was trying to understand some concepts from one of the articles when I glimpsed the article year and to my surprise: 1996. Wow! I wasn’t looking for an history class so I moved on.

I have found other older articles in the way and even have tried on some code until I was pointed to the right direction by some buddies. That’s a big point of confusion to beginners and inexperienced Java developers in my opinion. There is a ton of information about Java out there and we must take care not to get caught by some old and deprecated functionality. But since I got it right let’s stop complaining and go strait to the point!

(more…)

Scripts

Sunday, May 13th, 2007

Here you can find a list of all scripts that I have published so far here in my blog. This is just a more concise list of the same posts that you can find in the archives.

EasyDrag jQuery Plugin

EasyDrag is a jQuery plugin aimed to provide a simple way of adding drag-and-drop functionality to DOM elements. It features the ability to set functions to be called on drag and on drop events.

XML Generator DIR

XML Generator DIR is an XML generator that will make a lot easier for you to create XML configuration files. It is focused in the creation of configuration files for image galleries, music players and for any other stuff where you need to list all files in a directory in a simple way.

XML Generator DB

It is a new XML Generator flavor aimed to build XML files based on records from a database table instead of files in a directory.

Auto-Complete Field with jQuery, JSON & PHP

An easy to implement auto-complete field based on the Ajax technology coded with the jQuery JavaScript library. It uses JSON and has an example of how to implement the backend script with PHP.

XML Generator DIR

Sunday, May 13th, 2007

XML Generator DIR is an XML generator that will make a lot easier for you to create XML configuration files. It is focused in the creation of configuration files for image galleries, music players and for any other stuff where you need to list all files in a directory in a simple way.

This script uses a model file to give you freedom defining your XML file. You can create practically any structure you want and let the script populate it for you.

If you need to read records from a database instead of directories in a filesystem you should check the XML Generator DB instead.

(more…)

XML Generator DB

Sunday, May 13th, 2007

Here is a new flavor of the XML Generator, called XML Generator DB. This version builds XML files based on records from a database table instead of files in a directory.

I was thinking about embedding this functionality into the original script (now called XML Generator DIR to follow the name pattern) but it would add a lot more complexity in its configuration. The usage is pretty similar to the original, the model is the same but with different placeholders.

If you need to list files from directories in a filesystem instead of a database you should check the XML Generator DIR instead.

(more…)

XML Generator 2.0 - PHP & DOM

Friday, May 11th, 2007

Update: I have updated and fixed some minor functionalities of this script and also changed its name to XML Generator DIR to differentiate from the new flavor XML Generator DB. Although the usage still the same you should check the new post instead.

So here it is! The 2nd version of the XML generator that will make a lot easier to create XML configuration files. As the previous version this one is focused in the creation of configuration files for image galleries, music players and related stuff where you need to list all files in a directory. The difference is that in this version you can create almost any XML structure in a simpler way.

While writing the 1st-version post I had this idea to use a model file instead of tweaking PHP variables and arrays. Different from before now you have freedom to define your XML file. You can have how many nested tags you want and also you can have attributes.

Writing this script was fun. I used PHP and the DOM library for the job. I won’t be explaining the code in details here because it already has a lot of comments but I may write a post explaining the DOM in more details based on readers feedback.

(more…)

XML Config File Generator with PHP

Wednesday, May 9th, 2007

Although this version may be an interesting study, you should check the new version instead. XML Generator 2.0 is easier and more powerful than the version presented in this post. Check it by clicking here.

This morning a friend of mine came to me asking for a script to automatically generate an XML config file. He needed a script to read directories of images and build an XML file for each one to use along his Flash gallery. It would save him a lot of time so I decided to write one specially for him. Then I realized that creating this type of XML file is a common task that many of us need to do at least once in a lifetime. Who never needed to create an XML for an image gallery or for a music player?

With this assumption in mind I decided to write a little more generic script. However, it’s still limited to the purpose of reading directories of one level only and for tags without attributes. In this post I’ll explain how you can use the XML generator script. I’ll not explain the code in details because I believe the source code is pretty well documented but if you have any doubt about it, please feel free to leave a message. I’ll be glad to help.

(more…)

SimpleXML debug with var_dump() and print_r()

Tuesday, May 8th, 2007

Recently I was using the SimpleXML extension from PHP5 to build a menu based on information contained in an XML file. I was using XPath queries to retrieve specific nodes from the XML tree and the var_dump() and print_r() functions to debug the results.

I thought my XPath queries were all wrong because the output data wasn’t the expected, all tree was returned instead. I tried many variations without success until I realized that something was wrong with the output. I let the debug functions aside and finished the code. And guess what? The code worked fine!

To confirm it I went to the manual to seek for any related information. No official note but I found an user comment about var_export not working as well!

So that’s it. Don’t use var_dump() nor print_r() to debug the content of SimpleXMLElement objects. Instead use print() or echo() on individual elements.

Update: I have also noticed a similar behavior with the DOM library.

Auto-Complete Field with jQuery - Code Explained

Tuesday, May 8th, 2007

Hello! As I promised, I’ll be explaining all the JavaScript code of the auto-complete field in this post. If you haven’t read the previous post where I talk about the auto-complete field take a moment to read it first before continuing.

Now take some cookies because the post is quite long. Be comfortable and let’s start!

(more…)

Auto-Complete Field with jQuery, JSON & PHP

Saturday, May 5th, 2007

In the last few days I’ve started using the jQuery JavaScript library. To experiment with this great piece of software I’ve decided to implement an AJAX auto-complete feature. jQuery makes remote scripting a piece of cake and that led me to spend more time coding additional functionalities for the auto-complete field. In this post I’ll explain how to use my auto-complete field and in a following post I’ll explain all the code. So let’s start!

(more…)

Back and Recast

Wednesday, May 2nd, 2007

Hello, this is my first post since the return of my blog. Different from before, when I used to post about my life and friends, now I’ll try to post some interesting and useful stuff for the community. Things that I have coded and learned during the years and that now are lost in the deepest folders of my hard drives will also appear.

At first, the idea is to post things related mainly to web development and programming, but it’s not a strict rule. I’ll try to keep posts constant and I’d like to hear back from you, even to correct my English mistakes.

If you want to know a little more about this blog take a look at the About page.

See you!