Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6864037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:51:41+00:00 2026-05-27T02:51:41+00:00

I am using this link to generate XML file using DOM. It says that

  • 0

I am using this link to generate XML file using DOM. It says that “Xerces parser is bundled with the JDK 1.5 distribution.So you need not download the parser separately.”

However, when I write the following line in my Eclipse Helios it gives compile-time error even though I have Java 1.6 in my system.

import org.apache.xml.serialize.XMLSerializer;

Why is it so?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:51:42+00:00Added an answer on May 27, 2026 at 2:51 am

    Xerces is indeed bundled with the JDK but you should use it with the JAXP API under javax.xml.parsers. Check the output of the program below.

    Also, to serialize an XML Document, you should use DOM Level 3 Load and Save (present in the JDK) or an XSLT transformation with no stylesheet (identity transformation). The rest is dependent on a specific implementation. The Xerces XMLSerializer is deprecated:

    Deprecated. This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP’s Transformation API for XML (TrAX) for serializing XML. See the Xerces documentation for more information.

    Here is an example of serialization with DOM level 3:

    import org.w3c.dom.*;
    import org.w3c.dom.bootstrap.DOMImplementationRegistry;
    import org.w3c.dom.ls.*;
    
    public class DOMExample3 {
    
        public static void main(String[] args) throws Exception {
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();    
            DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("XML 3.0 LS 3.0");
            if (impl == null) {
                System.out.println("No DOMImplementation found !");
                System.exit(0);
            }
    
            System.out.printf("DOMImplementationLS: %s\n", impl.getClass().getName());
    
            LSParser parser = impl.createLSParser(
                    DOMImplementationLS.MODE_SYNCHRONOUS,
                    "http://www.w3.org/TR/REC-xml");
            // http://www.w3.org/2001/XMLSchema
            System.out.printf("LSParser: %s\n", parser.getClass().getName());
    
            if (args.length == 0) {
                System.exit(0);
            }
    
            Document doc = parser.parseURI(args[0]);
    
            LSSerializer serializer = impl.createLSSerializer();
            LSOutput output = impl.createLSOutput();
            output.setEncoding("UTF-8");
            output.setByteStream(System.out);
            serializer.write(doc, output);
            System.out.println();
        }
    }
    

    Here is an example with an identity transformation:

    import org.w3c.dom.Document;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.OutputKeys;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    
    public class DOMExample2 {
        public static void main(String[] args) throws Exception {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder parser = factory.newDocumentBuilder();
    
            System.out.println("Parsing XML document...");
            Document doc;
            doc = parser.parse(args[0]);
    
            // Xerces Java 2
    
            /* Deprecated. This class was deprecated in Xerces 2.9.0.
             * It is recommended that new applications use the DOM Level 3
             * LSSerializer or JAXP's Transformation API for XML (TrAX)
             * for serializing XML and HTML.
             * See the Xerces documentation for more information.
             */  
            /*
            System.out.println("XERCES: Displaying XML document...");
            OutputFormat of = new OutputFormat(doc, "ISO-8859-1", true);
            PrintWriter pw = new PrintWriter(System.out);
            BaseMarkupSerializer bms = new XMLSerializer(pw, of);
            bms.serialize(doc);
    */
            // JAXP
    
            System.out.println("JAXP: Displaying XML document...");
            TransformerFactory transFactory = TransformerFactory.newInstance();
            System.out.println(transFactory.getClass().getName());
            //transFactory.setAttribute("indent-number", 2);
            Transformer idTransform = transFactory.newTransformer();
            idTransform.setOutputProperty(OutputKeys.METHOD, "xml");
            idTransform.setOutputProperty(OutputKeys.INDENT,"yes");
            // Apache default indentation is 0
            idTransform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");                
            Source input = new DOMSource(doc);
            Result output = new StreamResult(System.out);
            idTransform.transform(input, output);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this approach to display an icon near each link to a file
Using this file as source, I have a situation where I need to retrieve
I am traversing an XML file (that contains multiple tables) using XSLT. Part of
I'm using the Ajax.ActionLink helper to generate a link to delete a record. This
I am trying to get xml file from url link . This code for
I have installed Qt for windows CE using this link http://qt.nokia.com/products/platform/qt-for-windows-ce for visual studio8,
This link describes an exploit into my app using fckEditor: http://knitinr.blogspot.com/2008/07/script-exploit-via-fckeditor.html How do I
i have a problem using the Catch Clipboard Events code found on this link
I'm using WCF through Spring.net WCF integration link text This works relatively fine, however
I got this code in order to build an url for the link using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.