DE RECORDSET A XML
EsTA ES una funcion muy util que lo que hace es tomar una consulta SQL, ejecutarla contra el servidor y el resultado lo transforma en un XML.
el unico requisito de esta funcion es que asume una coneccion llamada
CONEXION
se ejecuta asi
Código PHP:
dim xml ,str
str = "select * from tabla"
xml = setQueryToXml(str)
y listo, en la variable xml estan tus datitos.
Código asp:
Ver originalFunction setQueryToXml(strSQL)
Dim strXMLTemplate
Dim xCount
Dim strXml
DIM dbcRec
DIM XMLOBJ
DIM XMLTEMPLATE
DIM XMLRESULT
on error resume next
Const adCmdText = &H0001 ' ADDED PARA PODER CONTAR
Const adOpenStatic = 3 ' ADDED PARA PODER CONTAR
Set dbcRec = Server.CreateObject("ADODB.RecordSet")
dbcRec.Open strSQL,ConEXION,adopenstatic,adcmdtext ' ADDED PARA PODER CONTAR
If Err.Number <> 0 OR dbcRec.RecordCount <= 0 Then
setQueryToXml = FALSE
Else
Set xmlObj = Server.CreateObject("MSXML2.DOMDocument")
Set XmlTemplate = Server.CreateObject("MSXML2.DOMDocument")
strXMLTemplate = "<?xml version=""1.0""?>"
strXMLTemplate = strXMLTemplate & "<xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" xmlns:z=""#RowsetSchema"" xmlns:rs=""urn:schemas-microsoft-com:rowset"">" & vbCrLf
strXMLTemplate = strXMLTemplate & "<xsl:output method=""xml"" cdata-section-elements=""id_objeto"" indent=""yes"" omit-xml-declaration=""yes""/>" & vbCrLf
strXMLTemplate = strXMLTemplate & "<xsl:template match=""/"">" & vbCrLf
strXMLTemplate = strXMLTemplate & "<xsl:element name=""cryptic_writings"">" & vbCrLf
strXMLTemplate = strXMLTemplate & "<xsl:for-each select=""/xml/rs:data/z:row"">" & vbCrLf
strXMLTemplate = strXMLTemplate & "<xsl:element name=""reg"">" & vbCrLf
For xCount = 0 To dbcRec.Fields.Count - 1
strXMLTemplate = strXMLTemplate & "<xsl:element name=""" & lcase(dbcRec(xCount).Name) & """>" & vbCrLf
strXMLTemplate = strXMLTemplate & "<xsl:value-of select=""@" & dbcRec(xCount).Name & """/>" & vbCrLf
strXMLTemplate = strXMLTemplate & "</xsl:element>" & vbCrLf
Next
strXMLTemplate = strXMLTemplate & "</xsl:element>" & vbCrLf
strXMLTemplate = strXMLTemplate & "</xsl:for-each>" & vbCrLf
strXMLTemplate = strXMLTemplate & "</xsl:element>" & vbCrLf
strXMLTemplate = strXMLTemplate & "</xsl:template>" & vbCrLf
strXMLTemplate = strXMLTemplate & "</xsl:stylesheet>" & vbCrLf
XmlTemplate.loadXML (strXMLTemplate)
dbcRec.Save xmlObj, 1
strXml = xmlObj.transformNode(XmlTemplate)
Set XmlTemplate = Nothing
Set xmlObj = Nothing
dbcRec.Close
Set dbcRec = Nothing
setQueryToXml = strXMLTemplate
setQueryToXml = strXml
End If
on error goto 0
End Function