Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: where can i get a Dom Parser jar ?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default where can i get a Dom Parser jar ?

    hi all,
    i have to work with
    javax.xml.parsers.DocumentBuilder;
    javax.xml.parsers.DocumentBuilderFactory;
    org.w3c.dom.Document;
    org.w3c.dom.Element;
    org.w3c.dom.NodeList;
    classes like ...etc
    i want to download that jar. i don't know jar file name.
    plzzzz, if u know that name of jar file name
    and where can i get that jar file ?
    could u tell me? plzzzzz
    thank u all


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,282
    My Mood
    Happy
    Thanks
    70
    Thanked 158 Times in 154 Posts

    Default Re: where can i get a Dom Parser jar ?

    They should all be a part of the standard Java SE installation.

    DocumentBuilderFactory (Java Platform SE 6)

    // Json

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: where can i get a Dom Parser jar ?

    The XML parser world is a dynamic one. As standards change, the parsers change as well--XML parsers are becoming more sophisticated. For most programming projects, the parser, at minimum, must support DOM Level 2, SAX 2, XSLT, and Namespaces. All the parsers discussed here provide these capabilities; however, there are distinct differences in performance, reliability, and conformance to standards. In this article, I'll compare the latest parsers from Sun, Oracle, and the Apache Software Foundation.

    Apache parser
    The Apache parser version 1.2.3 (commonly known as Xerces) is an open-source effort based on IBM's XML4J parser. Xerces has full support for the W3C Document Object Model (DOM) Level 1 and the Simple API for XML (SAX) 1.0 and 2.0; however it currently has only limited support for XML Schemas, DOM Level 2 (version 1). Add the xerces.jar file to your CLASSPATH to use the parser. You can use Xalan, also available from Apache's Web site, for XSLT processing. You can configure both the DOM and SAX parsers. Xerces uses the SAX2 method getFeature() and setFeature() to query and set various parser features. For example, to create a validating DOM parser instance, you would write:
    HTML Code:
    DOMParser domp = new DOMParser();
       try {
          domp.setFeature ("http://xml.org/dom/features/validation", true);
       } catch (SAXExcepton ex) {
          System.out.println(ex);
       }
    Other modifiable features include support for Schemas and namespaces.

    The following example shows a minimal program that counts the number of <servlet> tags in an XML file using the DOM. The second import line specifically refers to the Xerces parser. The main method creates a new DOMParser instance and then invokes its parse() method. If the parse operation succeeds, you can retrieve a Document object through which you can access and manipulate the DOM tree using standard DOM API calls. This simple example retrieves the "servlet" nodes and prints out the number of nodes retrieved.
    HTML Code:
    import org.w3c.dom.*;
    import org.apache.xerces.parsers.DOMParser;
    
    public class DOM
    {
        public static void main(String[] args) 
        {
    
            try {
                DOMParser parser = new DOMParser();
                parser.parse(args[0]);
                Document doc = parser.getDocument();
    
                NodeList nodes = doc.getElementsByTagName("servlet");
                System.out.println("There are " + nodes.getLength() + 
                   "  elements.");
    
            } catch (Exception ex) {
                System.out.println(ex);
            }
        }
    }
    You can use SAX to accomplish the same task. SAX is event-oriented. In the following example, inherits from DefaultHandler, which has default implementations for all the SAX event handlers, and overrides two methods: startElement() and endDocument(). The parser calls the startElement() method each time it encounters a new element in the XML file. In the overridden startElement method, the code checks for the "servlet" tag, and increments the tagCounter counter variable.. When the parser reaches the end of the XML file, it calls the endDocument() method. The code prints out the counter variable at that point. Set the ContentHandler and the ErrorHandler properties of the the SAXParser() instance in the main() method , and then use the parse() method to start the actual parsing.

  4. The Following User Says Thank You to balahton For This Useful Post:

    Json (November 26th, 2009)

  5. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,282
    My Mood
    Happy
    Thanks
    70
    Thanked 158 Times in 154 Posts

    Default Re: where can i get a Dom Parser jar ?

    Also when choosing the parser to use you should keep in mind what you actually need it for.

    Are you just parsing a simple config file or do you plan on parsing a gigantic sized xml?

    Is the xml file flat or very complex with namespaces etc?

    Do you have access to a schema so you could use the JAXB bindings?

    // Json