Ver Mensaje Individual
  #114 (permalink)  
Antiguo 23/12/2008, 06:17
Avatar de Muzztein
Muzztein
 
Fecha de Ingreso: agosto-2002
Ubicación: Hangar 18
Mensajes: 1.703
Antigüedad: 21 años, 8 meses
Puntos: 16
Respuesta: Biblioteca de Clases,Funciones y Sub-rutinas.

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 original
  1. Function setQueryToXml(strSQL)
  2.    
  3.  
  4.  
  5.     Dim strXMLTemplate
  6.     Dim xCount
  7.     Dim strXml
  8.     DIM dbcRec
  9.     DIM XMLOBJ
  10.     DIM XMLTEMPLATE
  11.     DIM XMLRESULT
  12.                 on error resume next
  13.                
  14.                 Const adCmdText = &H0001 ' ADDED PARA PODER CONTAR
  15.                 Const adOpenStatic = 3   ' ADDED PARA PODER CONTAR
  16.  
  17.  
  18.                 Set dbcRec = Server.CreateObject("ADODB.RecordSet")
  19.                 dbcRec.Open strSQL,ConEXION,adopenstatic,adcmdtext  ' ADDED PARA PODER CONTAR
  20.                
  21.                 If Err.Number <> 0 OR dbcRec.RecordCount <= 0 Then
  22.                 setQueryToXml = FALSE
  23.                 Else
  24.                     Set xmlObj = Server.CreateObject("MSXML2.DOMDocument")
  25.                     Set XmlTemplate =  Server.CreateObject("MSXML2.DOMDocument")
  26.                     strXMLTemplate = "<?xml version=""1.0""?>"
  27.                     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
  28.                     strXMLTemplate = strXMLTemplate & "<xsl:output method=""xml"" cdata-section-elements=""id_objeto"" indent=""yes"" omit-xml-declaration=""yes""/>"  & vbCrLf
  29.                     strXMLTemplate = strXMLTemplate & "<xsl:template match=""/"">"  & vbCrLf
  30.                     strXMLTemplate = strXMLTemplate & "<xsl:element name=""cryptic_writings"">"  & vbCrLf
  31.                     strXMLTemplate = strXMLTemplate & "<xsl:for-each select=""/xml/rs:data/z:row"">"  & vbCrLf
  32.                     strXMLTemplate = strXMLTemplate & "<xsl:element name=""reg"">"  & vbCrLf
  33.                     For xCount = 0 To dbcRec.Fields.Count - 1
  34.                     strXMLTemplate = strXMLTemplate & "<xsl:element name=""" & lcase(dbcRec(xCount).Name) & """>" & vbCrLf
  35.                     strXMLTemplate = strXMLTemplate & "<xsl:value-of select=""@" & dbcRec(xCount).Name & """/>" & vbCrLf
  36.                     strXMLTemplate = strXMLTemplate & "</xsl:element>" & vbCrLf
  37.                     Next
  38.                     strXMLTemplate = strXMLTemplate & "</xsl:element>"  & vbCrLf
  39.                     strXMLTemplate = strXMLTemplate & "</xsl:for-each>"  & vbCrLf
  40.                     strXMLTemplate = strXMLTemplate & "</xsl:element>"  & vbCrLf
  41.                     strXMLTemplate = strXMLTemplate & "</xsl:template>"  & vbCrLf
  42.                     strXMLTemplate = strXMLTemplate & "</xsl:stylesheet>"  & vbCrLf
  43.                     XmlTemplate.loadXML (strXMLTemplate)
  44.                     dbcRec.Save xmlObj, 1
  45.                     strXml = xmlObj.transformNode(XmlTemplate)
  46.                     Set XmlTemplate = Nothing
  47.                     Set xmlObj = Nothing
  48.                     dbcRec.Close
  49.                     Set dbcRec = Nothing
  50.                     setQueryToXml = strXMLTemplate
  51.                     setQueryToXml = strXml
  52.                 End If
  53.                 on error goto 0
  54. End Function