import javax.xml.parsers.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import java.sql.*; import java.io.*; import org.w3c.dom.*; public class UusDokument{ public static void main(String argumendid[]) throws Exception{ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection( "jdbc:odbc:yhendus2", "", ""); Statement st=cn.createStatement(); String lause="SELECT * FROM video;"; ResultSet rs=st.executeQuery(lause); Document d=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element juur=d.createElement("video"); d.appendChild(juur); while(rs.next()){ Element e=d.createElement("video"); juur.appendChild(e); Element p=d.createElement("pealkiri"); p.appendChild(d.createTextNode(rs.getString("pealkiri"))); e.appendChild(p); Element z=d.createElement("zanr"); z.appendChild(d.createTextNode(rs.getString("zanr"))); e.appendChild(z); Element t=d.createElement("tutvustus"); t.appendChild(d.createTextNode(rs.getString("tutvustus"))); e.appendChild(t); } Transformer t=TransformerFactory.newInstance().newTransformer(); t.transform(new DOMSource(d), new StreamResult(new FileOutputStream("Videolaenutus.xml"))); }catch(Exception viga){ viga.printStackTrace(); } } }