• 0

Cross Platform Programming


Question

I'm needing to write a program that reads an XML file as input and outputs another modified XML file.

I'm needing it to run in Linux (XFree) and Windows. What programming language should I write this in? I don't really like Java, but I like how cross platform it is. I would be willing to maintain some different sets of code for the Linux portion and the Windows portion, but would like to keep that to a minimal. I would really like my program to use the standard Window API for either system, (probably KDE or GNOME for X as they are the most supported throughout any windows manager).

Any recommendations?

-nic

Link to comment
Share on other sites

Recommended Posts

  • 0
Why reinvent the whell - hell why even use a wheel! Just use an XSL Transformation with a program that will apply a given XSL to a given XML file, for example use MSXSL.

I believe he wanted something cross-platform. Not microsoft-only.

Link to comment
Share on other sites

  • 0
but I'm not sure about the JDBC driver for Java

I've used the mysql JDBC before, and it is simple to use. In fact, I wrote a little class wrapper that you could use if you wanted.

import java.net.*;
import java.sql.*;
import java.io.*;
import java.util.*;

public class SQLConnection {

	java.sql.Connection connection;

	// Load the JDBC driver
    String driverName;
    String serverName;
    String portNumber = "3306";
    String mydatabase;
    String database;
    String url; // a JDBC url
    String username;
    String password;

	public SQLConnection(String username, String password, String database, String server) {
  this.username = username;
  this.password = password;
  this.database = database;
  this.serverName = server;
  driverName = "org.gjt.mm.mysql.Driver";
  mydatabase = serverName + ":" + portNumber; 
  url = "jdbc:mysql://" + mydatabase + "/"+ database;
  connect();
	}

	public SQLConnection(String username, String password, String database,
     	 String server, String driverName) {
  this.username = username;
  this.password = password;
  this.database = database;
  this.serverName = server;
  this.driverName = driverName;
  mydatabase = serverName + ":" + portNumber;
  url = "jdbc:mysql://" + mydatabase + "/"+ database;
  
  connect();
	}

	public SQLConnection(String username, String password, String database,
     	 String server, String driverName, String url) {
  this.username = username;
  this.password = password;
  this.database = database;
  this.serverName = server;
  this.driverName = driverName;
  this.url = url + database;
  mydatabase = serverName + ":" + portNumber;
  
  connect();
	}

	// Method to connect to the database
	public void connect() {
  
  connection = null;
  
  try {
      Class.forName(driverName).newInstance();
      Logger.log("SQL Driver loaded");
      connection = DriverManager.getConnection(url, username, password);
      Logger.log("Connection established to SQL server");
   	 } catch (java.lang.NoClassDefFoundError e) {
      System.out.println(e);
   	 } catch (ClassNotFoundException e) {
       	 System.out.println("Could not find the driver");
   	 } catch(java.lang.InstantiationException e) {
      System.out.println("Connection Error");
   	 }catch (SQLException e) {
       	 System.out.println(e + "\nCould not connect to the database");
   	 }catch (Exception e) {
      System.out.println(e);
   	 }
  
	}

	// Method to execute a query from the database
	public synchronized ResultSet executeQuery(String clientCommand) throws SQLException{
  ResultSet rs = null;
  if(!isConnected())
 	 reconnect();
  if(!connection.isClosed()) {	
 	 Statement stmt = connection.createStatement();
 	 rs = stmt.executeQuery(clientCommand);
 	 return rs;
  }
  else {
 	 reconnect();
 	 Logger.log("Reconnected to SQL server");
 	 Statement stmt = connection.createStatement();
 	 rs = stmt.executeQuery(clientCommand);
 	 return rs;
  }	
	}

	// Method to update the database
	public synchronized void executeUpdate(String clientCommand) throws SQLException{
  if(!isConnected())
 	 reconnect();
  if(!connection.isClosed()) {
 	 Statement stmt = connection.createStatement();
 	 stmt.executeUpdate(clientCommand);
  }
  else {
 	 reconnect();
 	 Logger.log("Reconnected to SQL server");
 	 Statement stmt = connection.createStatement();
 	 stmt.executeUpdate(clientCommand);
  }
	}

	// Reconnect to the database server
	private void reconnect() {
  try {
 	 Logger.log("Reconnecting to server");
 	 connection = DriverManager.getConnection(url, username, password);
  }
  catch(SQLException e) {
 	 Logger.logError(e);
  }
	}

	// Method used to test if we are connected to a server
	public boolean isConnected() {
  boolean returnVal = true;
  try {
 	 Statement stmt = connection.createStatement();
 	 ResultSet rs = stmt.executeQuery("show tables;");
  }
  catch (SQLException e) {
 	 String theError = e.toString();
      if(theError.startsWith("java.sql.SQLException: Communication link failure")) {
    returnVal = false;
      }
   	 }
   	 return returnVal;
    }   

}

Link to comment
Share on other sites

  • 0

I didn't think .NET was really cross platform yet, and I'm needing a cross platform solution now. Also the Visual Studio IDE is extremely expensive for my buisness, while Eclipse seems to be freely distributed. I have Visual Studio .NET academic version, but I can't use it to write things for my buisness, only for learning.

Thanks for the wrapper bithub! I'll put it to good use.

Any book recomendations for this Eclipse IDE? I have an old Java book, but the documentation doesn't seem to be working after I installed Eclipse off of my SuSE 9.1 DVD. I learn best from books, as oppose to online documentation. Although having context senstive help is REALLY helpful after I know my way around.

Link to comment
Share on other sites

  • 0

In case you have chosen/will choose the C++ route, there is a very small and simple XML library called TinyXML. It is implemented in standard C++ (as far as I can tell from what I have seen from the source) and thus portable. It doesn't let you exploit all XML features but should be sufficient if you're just worried about reading and writing simple XML files. If you need more there's always expat - with a steeper learning curve though.

Link to comment
Share on other sites

  • 0

C++ exe files are not portable. If he used C++, he would have to compile different version of the application in all different enviornments.

ie would need to compile the code in .

Windows

Unix

OSX

Solaris

Thats a lot of hassle interms of creating a cross platform application.

Link to comment
Share on other sites

  • 0

if youre looking for a cross platform language and toolkit then indeed look at C#. It has bindings for gtk which runs under linux, windows and even osx w/ no recompiling.

Link to comment
Share on other sites

  • 0
  C++ exe files are not portable. If he used C++, he would have to compile different version of the application in all different enviornments.

ie would need to compile the code in .

Windows

Unix

OSX

Solaris

Thats a lot of hassle interms of creating a cross platform application

Could be worse, he could try to write it without pointers :devil: .

Link to comment
Share on other sites

  • 0

Hm. For this kind of task I really do not see a reason to worry about the language choice.

It simply does not matter at all. You can write a program to read and write XML in many languages with almost same involvement.

So, just choose the language that is available on both these platforms and the one you know somehow (or at least the one you see an easy example to read/write XML files).

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.