Solved

which is the best language to implement a parser application

Posted on 2006-07-18
3
254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

756 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