HomeDigital EditionSys-Con RadioSearch Web Services Cd
B2B Beginning WS Business Process Management Case Studies Content Management Distributing Computing e-Business Electronic Data Interchange Enterprise Industry Insight Integration Interviews Java & Web Services .NET Portal Product Reviews Scalability & Performance Security SOAP Source Code UDDI Wireless WS Standards WS Tips & Techniques WSDL WS Editorials XML

Data - A Key Part of Web Services, by Brian C. Reed
WSJ Vol 02 Issue 05 - pg.13

	

Listing 1 // Sample SQL SELECT of XML data // Inventory.XML is the XML file containing // well-formed hierarchical XML data SQLDriverConnect (hdbc, DSN="XMLDataSource"...) SQLExecDirect (hstmt, "Select * from Inventory", SQL_NTS) // Sample SQL SELECT with relational to XML persistence // Parts is the relational table of parts information // that will be persisted into XML file SQLDriverConnect (hdbc, DSN="OracleDataSource"...) SQLExecDirect (hstmt, "Select * from Parts", SQL_NTS) SQLSetStmtAttr (hstmt, SQL_PERSIST_AS_XML, "//myweb/inventorylist/parts.xml", SQL_NTS) Listing 2 // Connect and execute statement stmt = conn. createStatement(); rs = stmt. executeQuery(" select * from inventory"); // Create and populate the WebRowSet WebRowSet wrs = new WebRowSet(); wrs. populate(rs); // close the connection conn. close(); // Iterate through WebRowSet that contains values... wrs. next(); // write the RowSet out as XML wrs. writeXML( out); Listing 3 //Create statement SqlCommand command = new SqlCommand(); command.CommandType = System.Data.CommandType.Text; command.CommandText = "select * from inventory"; command.Connection = con; //Populate DataSet with results of select DataSet dsInventory = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = command; adapter.Fill(dsInventory,"Inventory"); //Get DataTable from DataSet DataTable myDt = dsInventory.Tables[0]; // Iterate for each row foreach (DataRow r in myDt.Rows) ... //Write DataSet as XML dsInventory.WriteXml(writer);