Solved

which is the best language to implement a parser application

Posted on 2006-07-18
3
253 Views
Last Modified: 2013-11-23
I want to convert XML to python classes .Please suggest me how to procedd..
i mean which language is best to implement the parser application to convert from xml file  to python classes..

i ahve some basic knowledge of java , c++ and python ..

please let me know about libraries to be used for the same parser application !

thanks in advance


0
Comment
Question by:futurelogix
3 Comments
 
LVL 15

Accepted Solution

by:
bpmurray earned 250 total points
ID: 17131351
Unfortunately "best" always starts a religious discussion. The reality is that all three (java, C++ and python) can be used. Personally, I prefer Java since it has a wealth of solutions for XML manipulation. You probably will want to use DOM manipulation, so that's what I'll focus on. Expect lots of solutions based on every possible language :-)

JAXP (Java API for XML Processing) is a Java interface to allow consistent parsing of XML documents, which is just what you want to do. It's easy to use and there's lots of info available on the web. Actually, there are loads of different libraries, so this is just one solution, but pretty standard. The code below will load & parse your file, and processing the document is pretty easy after that. Search Google for "JAXP parser" or similar and you'll get a lot of pretty relevant hits.

One point: Apache Xerces and XML4J are other libraries, but JAXP is the best of the lot, IMHO.

import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


public class LoadXMLDocument
{
    public static void main(String[] args)
    {
       String myInputSource= "pythonStuff.xml";
       try{
          // First, you need a document factory
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          // Next, you need a parser
          DocumentBuilder parser = factory.newDocumentBuilder();
          // Load file into document DOM
          Document doc = parser.parse(myInputSource);
       } catch(Exception ex){
         System.out.println(ex.getMessage());
       }
       // OK, now we have our DOM
  }
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question