Solved

which is the best language to implement a parser application

Posted on 2006-07-18
3
251 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now