• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is scripting an improper usage of XML?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was pondering about something very basic � Regarding the use of XML for scripting, as in ant, for example.

The basic notion is that XML is used for data representation.
In this regards, some of the valid uses of XML would be like:
Sending data across different systems as request/response
Storing configuration data, (as an alternative to properties files). E.g, the Log4J framework uses XML files to store configuration details

As far as XML based scripting is concerned, like apache ant, I still cannot find the logic behind using XML for scripting; although I'm perfectly comfortable with Ant.
I'm also wondering if this approach is completely a misuse of XML and wrong altogether, or, if there is some advantage for using XML for scripting, which I am not able to realize.

Please throw in your opinions and thoughts in this regard.

Cheers,
Sandeep

[ July 28, 2008: Message edited by: Sandeep Narasimhamurthy ]
[ July 28, 2008: Message edited by: Sandeep Narasimhamurthy ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm also wondering if this approach is completely a misuse of XML and wrong altogether, or, if there is some advantage for using XML for scripting, which I am not able to realize.



What an odd question!
The XML police will not come get you if you use XML for anything at all, as long as you follow the specification.

The advantages of XML (IMHO) are:
1. human and machine readable
2. Unicode compatible
3. Xpandable structure - which means a properly designed application won't break if you decide to add new elements.
4. lots of tools

For me, 3 has been most important. I use XML to define exam question scripts. I have been able to add new question types to the scripts and presentation engine without breaking existing material.

Bill
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On a more philosophical level, script code is data - for the script interpreter.

Whether you influence the running of a program implicitly by putting data into an XML file, or if you do so explicitly by putting commands into the file - that's a fine line, and I'd say not really a useful distinction to begin with.
 
Sandeep Murthy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,

Sorry if my question sounded odd.

I know the advantages of XML too. I'm also aware that the XML police will not come and get me (lucky me)

But my doubt was regarding using XML for scripting tools like ANT.
I feel writing scripts in XML is a non intuitive approach. Because, XML is best suited for representing data, for all the advantages that you already quoted. But for scripting, something like a programming language will be more suited and intuitive.

If you have used ANT, you would understand the point I'm trying to make here.
Take a simple ant build script for example:

<target name="-compile" description="Compiles code">
<echo>Checking if required jar is present in the directory abc</echo>
<available file="xyz.jar" property="xyz.available"/>
<fail unless="xyz.available" message="Unable to find xyz.jar..Exiting Build..."/>
<echo>Found xyz.jar in the directory abc</echo>
<mkdir dir="build"/>
<mkdir dir="classes"/>
<mkdir dir="temp"/>
<copy todir="temp" file="file_list.txt"/>
<javac srcdir="src" includesfile="temp/file_list.txt" destdir="classes" debug="yes">
<classpath refid="classpath"/>
</javac>
<delete dir="temp"/>
</target>

What is happening above is a series of logical steps being carried out one after the other. These logical steps are presented as XML tags. Here's where I was wondering. Does it make sense to represent a logical flow as XML tags; and for what advantage? Isn't it the work of a programming language to do tasks similar to above. Something like Perl, Unix shell scripts, DOS batch files, or plain java?

In a simple sudocode, the above build script would be something roughly equal to the below:

sysout(�checking if requird file is present...�);
if (�xyz.jar� exists)
{
sysout(�File found�);
mkdir �build�;
mkdir �classes�;
mkdir �temp�;
copy to temp �file_list.txt�;
javac srcdir=�src� includesfile="temp/file_list.txt" destdir="classes" debug="yes";
delete dir temp;
}
else
{
echo �File not found�;
}

I'm not telling that ant is not a good tool. In fact, I do like the tool much and am very much dependent on the tool myself.
But do you think this is proper usage of XML?
[ July 28, 2008: Message edited by: Sandeep Narasimhamurthy ]
 
Sandeep Murthy
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Humm... That's a nice way of analyzing it Ulf, makes a lot of sense, thanks.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sandeep Narasimhamurthy:
Does it make sense to represent a logical flow as XML tags; and for what advantage? Isn't it the work of a programming language to do tasks similar to above. Something like Perl, Unix shell scripts, DOS batch files, or plain java?

Well, sure it's the job of a programming language to do tasks like that. But notice that many programming languages -- most languages, in fact -- are basically nodes organized in a tree. Java certainly is. And XML is ideal for organizing nodes in a tree, so it is not a bad choice for representing program code. So why not?
 
reply
    Bookmark Topic Watch Topic
  • New Topic