Hi,

I am trying to serialize from DOM to SAX using XMLSerializer. It hangs. 
However,if I serialize and direct to standard out, it works. I do not know what 
is wrong with it ? OR is there any way we can convert from DOM to SAX source.

Please find the attached java and xml files.


Thanks
Ajay


      
<Doc:Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:Doc="urn:swift:xsd:swift.eni$camt.028.001.02">
	<Doc:camt.028.001.02>
		<Doc:Assgnmt>
			<Doc:country1>USA</Doc:country1>
			<Doc:country2>CHINA</Doc:country2>
			<Doc:country3>BELGIUM</Doc:country3>
		</Doc:Assgnmt>
	</Doc:camt.028.001.02>
</Doc:Document>
import java.io.*;
import javax.xml.parsers.DocumentBuilderFactory ;
import javax.xml.parsers.DocumentBuilder ;
import javax.xml.parsers.ParserConfigurationException ;
import org.apache.xml.serialize.XMLSerializer;
import org.xml.sax.InputSource;
import org.w3c.dom.Document;
import javax.xml.transform.sax.SAXSource;

public class PrintDOMTree {
    public static void main(String[] args) {
        try {
            //InputSource source = new InputSource(args[0]);

          Document document= null;
          try
          {
              DocumentBuilderFactory dFactory = 
DocumentBuilderFactory.newInstance();
              DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
              try
              {
                  document = dBuilder.parse( new FileInputStream(args[0]));
              }
              catch( Exception e)
              {
                  System.out.println(e.toString());

               }
           }
           catch (Exception e)
           {
              System.out.println();
              System.out.println(e.toString());
           }

            PipedOutputStream pos = new PipedOutputStream();
            PipedInputStream pis = new PipedInputStream();
            pis.connect(pos);
            XMLSerializer serializer = new XMLSerializer();
            SAXSource source = new SAXSource( new InputSource(pis) );
            serializer.setOutputByteStream(pos);
            //serializer.setOutputByteStream(System.out);
            System.out.println("debug1");
            serializer.serialize(document);
            System.out.println("debug2");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}    

Reply via email to