Jump to content

From database to xml


xmlxpert
 Share

Recommended Posts

Hi, Do you think its alright if a site first connect first to a database and get a record and save this record to a xml file and read this file to a browser? Seemd like its time consuming isn't, you see im a asp newbie and connecting to a database with this is easy on me and so I decided to do that from here to there approach :).

Link to comment
Share on other sites

A much more speedy solution in my opinion would be for the database to contain the parts of the XML itself and the server side script would only have to assemble and/or transform the data there.

Link to comment
Share on other sites

boen, is there any way you can go into a little more detail with your explanation? I want to use xml and xsl to display the data from my MySQL db on the PHP problem I have posted in the PHP forum. I'm in the process of learning xml, and am learning PHP on my own. We haven't gotten to database integration in the xml class yet.Thanks for the help.Al

Link to comment
Share on other sites

PHP doesn't have XSLT processor built in as I have stated many times. Unless you find a way to install some kind of extension (see php.net for details on this one), you can't make PHP process the XSLT unless you create your own XSLT processor with PHP itself. I don't know much about PHP, so I can't give you a sample of what I mean.And about the above example I meant for example a database which has a record like

<hardware><ram>256mb</ram></hardware>

And another record with for example

<image><url>www.example.com/pic1.jpg</url><alt>pic1</alt></image>

And now let's say we have a PHP file which creates an instanse of a container div for example and catches the data in the <hardware> element. It then displays it and actually shows that the content from the <ram> element is RAM memory. The same is done for the <image> of the current row.Normally, if this was ordinary XML, you would have to transform the data with XSLT and execute it with a server side language. But as said above, PHP doesn't have XSLT support. It does have XML thoguh.This approach is better then to keep each SQL data in it's own record, because it makes the data more structured and expandable. Instead of having another table for the images, you have a single column which contain it. However, this is not always better. Infact, there are not many cases, where this prooves to be usefull.

Link to comment
Share on other sites

A much more speedy solution in my opinion would be for the database to contain the parts of the XML itself and the server side script would only have to assemble and/or transform the data there.

Hi, Is this code speedy enough? Im new with xml and asp. This script does is transform the data there as what you say or does it? :)default.asp
<%    dim xmlhttp,xmlDom,xsldom,Query    set xmlhttp=createobject("MSXML2.XMLHTTP")    set xmlDom=createobject("MSXML2.domdocument")    set xslDom=createobject("MSXML2.domdocument")        xmldom.async=false    xsldom.async=false    query = "<main><sql>select * from product</sql></main>"    xmlhttp.Open "POST","http://localhost/www\XML\xml_27/data.asp", false    xmlhttp.send query    if xmlhttp.status <> 200 then        response.write "Error !!!"   end if        xmldom.load xmlhttp.responseXML    xsldom.load server.mappath(".")+"/"+view    response.write XMLDom.transformNode(XSLDom)%><%set xmlhttp = nothingset xmldom= nothingset xsldom = nothing%>

data.asp

<% Option Explicit %><%Response.ContentType = "text/xml"%><?xml version="1.0"?><%   dim xmlDom   dim Conn,rs,fld,query   set xmlDom=createobject("MSXML2.domdocument")   Set Conn = server.CreateObject("adodb.connection")   set rs = server.createobject("adodb.recordset")   xmldom.load request   query = xmldom.documentElement.childNodes(0).text    Conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+server.mappath(".")+"\database.mdb;Persist Security Info=False"   rs.open query,conn,3,1 %><recordset total="<%=rs.recordcount%>"><head><%for each fld in rs.fields%><field name="<%=fld.name%>"/><%next%></head><rows><%do until rs.eof%><row><%for each fld in rs.fields%><col><%=fld.value%> </col><%next%></row><%rs.movenext%><%loop%></rows></recordset><%rs.closeconn.closeset conn = nothingset rs= nothingset xmldom = nothing%>

Link to comment
Share on other sites

Actually, if you're going to use ASP, it's MUCH better to store different types of data in both SQL and XML depending on their purpose. SQL for catalogue purposes, and XML for all other data (most often- interface data such as the titles for the different links). Using XSLT you can transform the data more... clearly and use ASP only to execute the transformation and manipulate the database.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...