Archive for the ‘XML’ Category

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…)

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.