0

Possible Duplicate:
How to keep whitespace before document element when parsing with Java?

I'm trying to parse the xml so that i can replace the latin characters. latin characters within the xml is getting replaced, but \n and \t present within the xml are getting deleted. i'm using the dtd for replacing latin characters. Below is the code i've used for parsing the xml

DocumentBuilderFactory docFactory = DocumentBuilderFactory
                .newInstance();
        docFactory.setValidating(false);
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        docBuilder.setEntityResolver(resolver);
        String str = "";
        try {
            Document doc = docBuilder.parse(is, contextPath);
            OutputFormat format = new OutputFormat(doc); // Serialize DOM
            format.setIndenting(reqIndent);
            format.setOmitDocumentType(true);
            format.setEncoding(encoding);
            StringWriter stringOut = new StringWriter(); // Writer will be a
            XMLSerializer serial = new XMLSerializer(stringOut, format);
            serial.asDOMSerializer(); // As a DOM Serializer
            serial.serialize(doc);
            str = stringOut.toString();
        } catch (org.xml.sax.SAXParseException saxExp) {
            throw saxExp; // asString(is);
        } catch (Exception e) {

            throw e;

        } finally {
            if (is != null)
                is.close();
        }
        return str;
Community
  • 1
  • 1
nithin
  • 387
  • 3
  • 9
  • 20

0 Answers0