Java parser

Can anyone tell where can i get an XML->DOM parser for java?
TIA

such a parser is part of the jdk 1.4 http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html
another parser is xerces
http://xml.apache.org/xerces2-j/index.html

Similar Messages

  • Looking for a Java Parser

    Hi,
    I'm working on a Web Service Project, and i'm trying to deploy Web Services dynamically. Now the problem is, that i have to adapt the Java src-files sometimes before the deployment (Like adding Annotations, Methods or just peaces of code into a Method. So what i'm looking for is some Sort of a Java Parser, that gives me information on where to insert the code i generated.
    Simple example:
    public class WSExample{
         public void doSomething(){
              //do something
    //this class should be changed to something like this:
    public class WSExample{
         @WebMethod       //Annotation added
         public void doSomething(){
              //do something
            //this Method is generated automatically
            @WebMethod
            public void doSomethingDifferent{
                   //like establishing a connection to a different WS
    }All i've found up to now are parser generators like antlr or javacc. But i couldn't find anything about how to use the generated parsers or even manipulate the parsed code, yet. I hope i don't have to write a parser or grammar myself. Maybe someone can link me to some useful tutorial, forum or whatever else might be helpful.

    If you are using Sun's Java 1.4, you already have one. If you are using an ealier version, here are a couple of links:
    Xerces is probably the most feature rich:
    http://xml.apache.org/xerces2-j/index.html
    GNU JAXP is also good and very small:
    http://www.gnu.org/software/classpathx/jaxp/

  • How to use the build-in Java parser

    Hi All,
    I want do use the build-in Java parser. Is this possible? For example I have the following code:
    package ch.fhnw;
    import javax.tools.*;
    public class JavacExample {
         * @param args
        public static void main(String[] args) {
         JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
         String arguments = "./src/ch/fhnw/JavacExample.java";
         int rc = javac.run(null , null, null, "-verbose", arguments);
         System.out.println("Return value: " + rc);
    }After parsing, it would be great to have an object or similar which contains the methods, arguments used by the methods, etc. The target is to extract method declarations from java files. Is there a simple way to do it without defining my own EBNF like in JavaCC? Or any other way?
    Thank you for your help.
    kind regards,
    wolfgang

    Yep. bootstrap your knowledge here
    [http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html]
    [http://forum.java.sun.com/forum.jspa?forumID=514]
    Bruce

  • Fatal error in Java Parser V2 :Status??

    We still have a problem with entity references
    in V2 of the JAVA XML parser (see Rolf van Deuresen 24-11).
    It is a very urgent problem for us. We think that the XML-team
    is working on it. Can you inform me abouth the status with the
    (bug??)-fix. If you need more information on the problem, please
    ask.
    Greetings,
    Erik van den Berg.
    null

    Attachments: "1|type=text/plain|desc=SAXSample output|17142|file=output.txt|"
    Oracle XML Team wrote:
    : Erik van den Berg (guest) wrote:
    : : Oracle XML Team wrote:
    : : : Erik van den Berg (guest) wrote:
    : : : : We still have a problem with entity references
    : : : : in V2 of the JAVA XML parser (see Rolf van Deuresen 24-
    11).
    : : : : It is a very urgent problem for us. We think that the
    XML-
    : : team
    : : : : is working on it. Can you inform me abouth the status
    with
    : : the
    : : : : (bug??)-fix. If you need more information on the
    problem,
    : : : please
    : : : : ask.
    : : : : Greetings,
    : : : : Erik van den Berg.
    : : : Have you downloaded the latest version 2.0.2.5 that was
    made
    : : : available this week?
    : : : Oracle XML Team
    : : : http://technet.oracle.com
    : : : Oracle Technology Network
    : : I have downloaded the new version 2.0.2.5 of the Java
    parser,
    : : and it stil doesn't work. Please refer to the original
    message
    : : from Rolf van Deursen (24th november 1999) for the details.
    : : Maybe it will help you if I mail you a XML file that fails.
    If
    : : so, please give me your email account.
    : : Greetings,
    : : Erik van den Berg.
    : You can attach files to messages in the forum here.
    : Oracle XML Team
    : http://technet.oracle.com
    : Oracle Technology Network
    Here's the XML that raises the Fatal error. The following
    information is generated by the parser:
    Fatal Error of Java SAX parser v2.0.2.5:
    XML-0121: (Fatal Error) End tag does not match start
    tag 'WOONPLAATS'. at line 517, column 4151 of XML document.
    I attached the output of the SAXSample class, so you can trace
    the line and column where the error occurs. Also attached is the
    XML file (4Mb).
    An other error that occurs with this XML is the following
    situation:
    <VOLGNR_FILM> 001</VOLGNR_FILM>
    this piece of XML is parsed with the following events:
    StartElement:VOLGNR_FILM
    Characters:NR_
    Characters:001
    EndElement:VOLGNR_FILM
    So the spaces are replace with a part of the start tag! This is
    also only with large files. I tested this piece of XML in a
    seperate file. Then it was parsed correctly.
    Kind regards,
    Erik.
    null

  • How can i build a java parser/interpreter

    How can i build a java parser/interpreter
    i know java offers a tokenizer, how can i use it for build a parser or interpreter that recognize tags like this:
    <query db="db1" select="row1, row2">
    and then perform some actions

    how can i use it for build a parser or interpreter that recognize tags like this:A compiler design class would help understand the issues involved.
    Or as suggested if you are merely trying to parse XML then there are variety of existing solutions.
    Of if not XML and you already understand the principles of compiler design (formally or perhaps with experience with lexx/yacc) then you could use JavaCC
    http://www.webgain.com/products/java_cc/

  • Setting content (Java parser)

    Hi, I'm using a Java parser to take in binary files.
    In windows explorer if I drag and drop on to an ifs
    it works fine, however if the file already exists
    then it is replaced by a 0 byte file of the same name.
    Heres the relevant parser code:
    public LibraryObject parse(InputStream inStream, ParserCallback callback, Hashtable options)
    dis = new DataInputStream(inStream);
    baos = new ByteArrayOutputStream();
    int b = -99;
    byte[] buffer = new byte[1024];
    try
    while((b = dis.read(buffer)) != -1)
    if(b < buffer.length)
    baos.write(buffer, 0, b);
    else
    baos.write(buffer);
    catch(EOFException e)
    DocumentDefinition docDef = new DocumentDefinition (m_librarySession);
    Collection allFormats = m_librarySession.getFormatExtensionCollection();
    docDef.setFormat((Format) allFormats.getItems("bin"));
    docDef.setClassname("BINARYFILE");
    docDef.setAttribute("NAME", AttributeValue.newAttributeValue(options.get(CURRENT_NAME_OPTION)));
    byte[] outbytes = baos.toByteArray();
    bais = new ByteArrayInputStream(outbytes);
    docDef.setContentStream(bais);
    Document newDoc = (Document)
    m_librarySession.createPublicObject(docDef);
    if(options.get(UPDATE_OBJECT_OPTION) != null)
    Document currentDoc = (Document) currentFolder.findPublicObjectByPath
    (docDef.getAttribute("NAME").toString());
    currentDoc.update(docDef);
    else
    currentFolder.addItem(newDoc);
    baos.close();
    //bais.close();
    //dis.close();
    As I said this only causes trouble if the file is already present in the ifs directory I'm placing it in.
    Thanks for your time,
    Cathal

    try moving this line:
    m_librarySession.createPublicObject(docDef);
    into the "else" block of your condition:
    else
    // move the line here
    currentFolder.addItem(newDoc);
    the mistake you're making is that you always create a new document, whether or not you want to update an existing document or not.
    this mistake causes two problems:
    1. when you're updating (i.e. the "if" block of your condition will execute) you leave the new document you created floating around.
    2. when you're updating, the existing document content gets set to 0 bytes. why? because you already sucked out all the bytes from your bais when you created the new document earlier! when you try to update the existing one later, the bais is already "at the end" and there's nothing left to read out. for more info about this you should read up on the java.io package.

  • Java parser for regular expression to java program

    Hi All,
    I am very new to parser technologies .I am looking for a (java)parser which can read the "regular expression" and can convert it into "java program".Please let me know is there any thing related to this.
    Thanks in advance.
    Your will be appriciate.
    Regards,
    Sai.

    Hi Jos,
    Thank you for your quick response .You're welcome.
    If you have any sample code or simple example for how to use those
    classes (Pattern,Match) ,will you please send me .It will be helpful for me.Jverd gave you two nice links already in his reply #3
    If there is any "open source" for parsering regular expressions.
    Please send me I am very new to parser technologies.Note that that Pattern class take care of all the parsing of REs, i.e. there's
    nothing 'interesting' left for you to do any parsing whatsoever. Can you
    elaborate a bit on what you exactly want to do and learn?
    kind regards,
    Jos

  • Java Parser 2 DOMSample not working properly

    Hi
    I downloaded the parser (v2) and am running the DOMSample.java
    with the sample file empl.xml as the input. The program
    successfully finds the tree and writes out the nodes correctly,
    but it never finds the node values (I made sure that there is a
    call to getNodeValue()). For example, The following
    XML file:
    <?xml version = "1.0"?>
    <!DOCTYPE parent [
    <!ELEMENT parent (child)>
    <!ELEMENT child (#PCDATA)>
    ]>
    <parent>
    <child>Murthy</child>
    </parent>
    The getNodeValue() always returns null, even though the <child>
    tag has a value.
    What am I missing?
    Thanks in advance
    Murthy.
    null

    You have to get the TEXT children of an element and then use the
    getNodeValue() method on the text nodes.
    Oracle XML Team
    James Lee (guest) wrote:
    : How do u do that? when i tried to pass it into a text node, the
    : runtime error says that there is a classcastexception.
    : James
    : Oracle XML Team wrote:
    : : As per the W3C DOM spec, getNodeValue() of an element is
    : always
    : : null. You need to pass it the text node to get the actual
    text.
    : : Oracle XML Team
    : : http://technet.oracle.com
    : : Oracle Technology Network
    : : Murthy Jarugumilli (guest) wrote:
    : : : Hi
    : : : I downloaded the parser (v2) and am running the
    : DOMSample.java
    : : : with the sample file empl.xml as the input. The program
    : : : successfully finds the tree and writes out the nodes
    : : correctly,
    : : : but it never finds the node values (I made sure that there
    : is
    : : a
    : : : call to getNodeValue()). For example, The following
    : : : XML file:
    : : : <?xml version = "1.0"?>
    : : : <!DOCTYPE parent [
    : : : <!ELEMENT parent (child)>
    : : : <!ELEMENT child (#PCDATA)>
    : : : ]>
    : : : <parent>
    : : : <child>Murthy</child>
    : : : </parent>
    : : : The getNodeValue() always returns null, even though the
    : : <child>
    : : : tag has a value.
    : : : What am I missing?
    : : : Thanks in advance
    : : : Murthy.
    Oracle XML Team
    http://technet.oracle.com
    Oracle Technology Network
    null

  • Java Parsing Problem.

    I'm trying to create a GWT app and trying to parse info from my gmail contacts but I'm getting a Null type error.
    I am using an input stream that gets the Xml data back from the contacts in gmail however when I try turn this into a string and parse it I hit problems.
    here is some of the code
    System.out.println("here we go " + toString(inputStream)); - This line works, it prints out the whole xml file
    String xml = toString(inputStream); - this doesn't, xml never gets set to anything, its just null
    Document xmlDoc = null;
    xmlDoc = XMLParser.parse(xml); - so this doesn't work either as xml is null
    Here is the toString() code
    public String toString(InputStream inputStream) throws IOException {
        String string;
        //System.out.println("Into toString()");
        StringBuilder outputBuilder = new StringBuilder();
        if (inputStream != null) {
          BufferedReader reader =
              new BufferedReader(new InputStreamReader(inputStream));
          while (null != (string = reader.readLine())) {
            outputBuilder.append(string).append('\n');
        return outputBuilder.toString();
      }I cant understand why when I print out toString(inputStream) it works but when I try to setting as the variable xml is doesn't work, it comes up as null?
    Any ideas?
    Edited by: draffodx on Apr 12, 2009 9:49 AM

    Thanks, that was helpfull,
    here is the code up until the xmlDoc now
    InputStream inputStream;
             if (responseCode == HttpURLConnection.HTTP_OK) {
               inputStream = connection.getInputStream();
               System.out.println("ipstream");
             } else {
               inputStream = connection.getErrorStream();
               System.out.println("ipstream error");
             System.out.println("gets to here");
             Document xmlDoc = XMLParser.parse(toString(inputStream));
                System.out.println("gets to here - 2");put I am still having the same problem, it gets to this line Document xmlDoc = XMLParser.parse(toString(inputStream)); but doesn't get any further, this is the first instance that the toString(inputStream) is used, is it still the same EOF problem that would be occurring?
    EDIT:
    This is the line its having trouble with now
    Document xmlDoc = XMLParser.parse(xml);
    this is the Error I get
    [WARN] StandardContext[]Exception while dispatching incoming RPC call
    com.google.gwt.user.server.rpc.UnexpectedException: Service method 'public abstract void org.developerworks.stocks.client.StocksService.displayMyItems(java.lang.String)' threw an unexpected exception: java.lang.ExceptionInInitializerError
         at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:360)
         at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:546)
         at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:164)
    <Text Removed>
    Caused by: java.lang.ExceptionInInitializerError: null
         at com.google.gwt.xml.client.XMLParser.<clinit>(XMLParser.java:28)
         at org.developerworks.stocks.server.StocksServiceImpl.displayMyItems(StocksServiceImpl.java:359)
    Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code!  It cannot be called, for example, from server code.  If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
    <Text Removed>
         at com.google.gwt.core.client.GWT.create(GWT.java:91)
         at com.google.gwt.xml.client.impl.XMLParserImpl.<clinit>(XMLParserImpl.java:29)
         at com.google.gwt.xml.client.XMLParser.<clinit>(XMLParser.java:28)
         at org.developerworks.stocks.server.StocksServiceImpl.displayMyItems(StocksServiceImpl.java:359)
         Edited by: draffodx on Apr 12, 2009 10:28 AM

  • Java parser for HTML 4.01

    Hi there
    i have to make a parser/DTD for HTML 4.01 , OR upgrade the existing parser of Java to Support HTML 4.01,
    Can any one help me out...
    regards

    is there some???
    That would be grate

  • Mobile XML transformation with MS or Java parser

    Dear all,
    I would like to set up an easy development environment for Mobile XML. For this reason, I would like to use a text editor (like emacs or notepad), and apply the Oracle 9iAS Wireless stylesheet (XSL file) to the Mobile XML with Internet Explorer parser.
    This works fine for a such file :
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?xml-stylesheet type="text/xsl" href="TINY_HTML.xsl"?>
    <SimpleResult>
         <SimpleContainer>
         </SimpleContainer>
    </SimpleResult>
    but does not work for the following one :
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?xml-stylesheet type="text/xsl" href="TINY_HTML.xsl"?>
    <SimpleResult>
         <SimpleContainer>
              <SimpleMenu>
                   <SimpleTitle>TP 9iAS Wireless</SimpleTitle>
              </SimpleMenu>
         </SimpleContainer>
    </SimpleResult>
    I have tried different XML/XSL parsers (MS, Java, XML Spy,...) but I got each time the same error message : "XSL parser stack overflow".
    Does anyone know a solution for this problem ?
    Thanks !
    Fabrice.

    I am not sure what the issue is, however within the next week or so, we will be offering an SDK on OTN with a small footprint (30MB) dev environment for Oracle9iAS Wireless. You will be able to use any IDE or text editor you wish.

  • PLEASE : JAVA PARSER SCHEMA XML doesn't work

    Hi,
    I search how can I parse a xml document with schema, which works with Sun'SAX in JAVA.
    I have no real idea to it, but I think that JAXP can work (is it a good idea?)
    I have found this exemple :
    http://dataml.net/articles/ValidateXMLSchema/part1.htm
    This example is often posted in the forum, but for me it doesn't work, and you? have you had a probleme with it?
    Have you others examples which work or tutorials for parse xml with schema with SAX in java?
    Furthermore what are the specifics recommandations to install JAXP ?
    Thanks a lots.

    Nobody can help me?
    please

  • Java parser api...

    Hi all,
    i am in need of a java api that should parse java .class, jar and other java files.
    Also it should compares old and new version of the java application in offline mode
    and gives changed,new and deleted classes and methods...
    thanks in advance...

    Please elaborate 'parse' in your sentence. This sounds very odd. Don't you mean 'decompile'?
    About the versioning: what about a version control system of the source code, like CVS?
    http://www.google.com/search?q=java+version+control
    http://www.google.com/search?q=java+source+control

  • Please help break our java parser

    Hello,
    We are working on making a Java code parser that will insert timestamp before and after any synchronized events (including wait(), notify() and notifyall()). It will parse in the source code, remove comments and carriage returns (replacing with spaces). It will then replace �{� with � { �, �;� with �; �, and also have
    while(stringA.indexOf(". ")>0)
    replace(". ", ".");
    We'll then splitting the source code by spaces and check each of the tokens to see if they are a synchronized method. If it isn�t then simply return the token however if they are we will add our logging around the token and then return that (i.e. logHere(); wait(); logHere().
    Is there any other possibilities that are not covered by the way we parse a Java code?
    Thanks for your help and time!
    -Team NN

    The problem I have is I can make the tree using an array but I need to know how to turn this into code to make the RegularExpression object to be returned.
    ie if RE entered by user is a|b, I know how to make it |ab in array
    if RE entered by user is ab, I know how to make it .ab in array
    I need to know how I can than use this to recursively generate the RegularExpression object. I don't have trouble with + and '|', but I dont know how to use a recursive method to return new sybol
    Example: If Regularexpression is abc I am able to get a string from the array .a.bc
    How do I make this a RE object. The tree is right associative so I know you have to use a preorder traversal, any ideas.
    Thanks for the help before hand.
    Thank you

  • How to create nested xml tags using java parser?

    Hi,
    I need to create a xml file containing following tags using java program-
    <A attr1="abc">
    <B attr2="xyz">
    <C attr3="pqr"> </C>
    </B>
    </A>
    Can anyone please let me know which parser should I use to create the above mentioned xml file?
    If possible, please post a code snippet for the same.
    Thanks in advance..

    Well, you could start by doing it all the 'old fashioned' way; create a String object containing that text and then write it away to a file. Or you could take the time to look at the javadoc for all of the xml support that the Java language itself supplies - XMLReader/Writer for a start. After that put together some code that you think would do the job and ask for help on any specific problems you encounter.

Maybe you are looking for

  • Is there any way to use iPod touch with Win2000/SP4?

    Got an iPod touch for christmas... very cool. It doesn't synch with my computer... not so cool. The information I've found - compatibility chart at http://docs.info.apple.com/article.html?artnum=60971 - suggests that I'm SOL with Win2000 - it appears

  • 10.2.0.3 Patch

    Tried to apply the 10.2.0.3 RDBMS patch to 10.2.0.1 Client. Installer stated there is nothing to patch. Is there a separate 10.2.0.3 patch for the 10.2.0.1 Client?

  • Accept IDOC function module.

    Hi Experts, I am new to IDOCS. I have to update one already written function module to accept IDOC in SAP from external system. In the function module I see some IMPORT parameters like 'input_method' and 'mass_processing' and EXPORT parameters like '

  • How can I delete a template

    The envelope templates provided generate a "media not loaded correctly".  I made my own that works, but in the process I made and saved one that also generates the  "media not loaded correctly" error.  I would like to get rid of that one (or at least

  • Mac Pro External/ Internal RAID for video

    I'm going to purchase a Mac Pro for use in video editing/capture. Use of Mac RAID card with internal drives (1TB) seems a good way to host applications and protect data, perhaps RAID 0+1. This could be a good starting point but I'm unsure if there wo