我怎样把这个字符串写到一个新创建的xml文件中,

解决方案 »

  1.   

    public static String writeDocumentIntoXml( Document doc,
                                                   String outFileName ){
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer;
            try{
                transformer= tf.newTransformer();
                DOMSource domSource = new DOMSource( doc );
                StreamResult sr = new StreamResult( new File( outFileName ) );
                try{
                    transformer.transform( domSource,sr );
                }catch( TransformerException ee ){            }
            }catch( TransformerConfigurationException e ){        }        return null;
        }