Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

which is the best language to implement a parser application

Posted on 2006-07-18
3
Medium Priority
?
262 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 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Progress
Suggested Courses

916 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