Solved

which is the best language to implement a parser application

Posted on 2006-07-18
3
252 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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