Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2003, 12:37 PM
Authorized User
 
Join Date: Oct 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Upload file

Hi all, I have a form written using JScript and XML ... which has 2 submit button - CD and Singer. When I enter a string to the text box and click on the CD submit button, it will display the data on the form. But, I also want it to put the data to a text file called "file.txt". When I click on the Singer button, it will diaply the data on the form too. And I also want the data append to the file.txt ... how can I do that? Eg in file.txt:

New Day Album
Celion Dion

Please suggest. Thank you very much.

 
Old October 24th, 2003, 01:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

What does this have to do with XML?

You may try your luck in one of the appropriate server-side technology forms, like the PHP or ASP forums (depending on what you're using or planning to use).

Regards,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 6th, 2003, 07:54 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by hbcontract
 [...] When I enter a string to the text box and click on the CD submit button [...] But, I also want it to put the data to a text file [...]
Recently, I have started using MS Remote Scripting; wich is a very simple technology which enables a page in the CLIENT, to use remote ASP methods in a SERVER, as if them where resident in the former...
Given that in a CLIENT you can't use the Scripting.FileSystem object, to access the file system in the hard disk of the CLIENT machine; such a remote execution of any method --suited to the requirements of your application--, will give you the tools to generate any XML document in the CLIENT Scripting, send it to the SERVER Scripting --without the need to reload the page-- wich in turn, would create and/or update the text file (same could be used to execute any SQL against a supporting database)... Furthermore: if you want --and write the proper code-- you will be able to get XML responses from the SERVER --all in the same request/response round trip, and again, without the need to reload the page--.

The mentioned technique uses the files RS.asp, RS.htm and RSProxy.class; which are installed with IIS --at least version 5.1 up-- on a directory named << _ScriptLibrary >> directly under the default Web root. You will find the corresponding documentation at MSDN in the next address:

http://msdn.microsoft.com/library/de...tml/rmscpt.asp.

I include here a working --but short-- sample, from an distributed application I am developing, wich uses a DHTML<--->XML<--->ASP<--->SQL<--->MSAccess200 model:

This example put at the disposal of a CLIENT, several methods for accessing a Table on an ACCESS 2000 Data Base stored on a Server. Such a methods are built over some SQL Queries (views), taken functionally seemingly as STORED PROCEDURES. Although the tasks accomplished are very simple, they are fully functional, and shows the basics on how could be implemented more complicated procedures for circumvent the load --and user hostile-- of CLIENT pages wich must be reloaded from the SERVER.

ANY COMMENTS AND/OR ERRORS SPOTTING ARE WELCOME.

IMPORTANT NOTE ABOUT THIS SCRIPTING CODE:

Two files are provided: One for the implementation of the Remote Class on the Server; and other for the implementation of a simple test bed of such a Class on the Client.



<!--

The set of methods implemented, are intended to enable a persistent variables schema, wich extends those capabilities of the IIS Application and Session Objects; allowing to preserve any desired values, of a given --and modifiable-- set of VARIABLES in a particular set of CONTEXTS.

The Table used by the methods herein implemented, have the following structure (given in Access 200 SQL):

             CREATE TABLE VariablesDeEstado (Contexto varchar(50),
                                     Variable varchar(50),
                                     Valor varchar(50))

The SQL queries (views) wich perform as stored procedures are described below:

             CreaVariable --> INSERT INTO VariablesDeEstado ( Contexto, Variable )
                                            SELECT [@Contexto] AS _Contexto,
                                                        [@Variable] AS _Variable;

             ActualizaVariable --> UPDATE VariablesDeEstado
                                             SET VariablesDeEstado.Valor = [@Valor]
                                             WHERE (((VariablesDeEstado.Contexto)=[@Contexto])
                                             AND ((VariablesDeEstado.Variable)=[@Variable]));

             ObtieneVariable --> SELECT VariablesDeEstado.Valor
                                             FROM VariablesDeEstado
                                             WHERE (((VariablesDeEstado.Contexto)=[@Contexto])
                                             AND ((VariablesDeEstado.Variable)=[@Variable]));

             EliminaContexto --> DELETE * FROM VariablesDeEstado
                                             WHERE Contexto=[@Contexto];

             EliminaVariable --> DELETE * FROM VariablesDeEstado
                                             WHERE (((VariablesDeEstado.Contexto)=[@Contexto])
                                             AND ((VariablesDeEstado.Variable)=[@Variable]));

The name of the Access 200 Database file is Sistema.mdb

A NOTE FOR ENGLISH PROGRAMMERS: ALL USER NAMES, MESSAGES AND ENTITIES ARE GIVEN IN SPANISH.

-->

<% RSDispatch %>



<script Id=InterfaseDelProxyRS runat=server language="javascript">

var public_description = new variablesClass();
function variablesClass()
{
    this.ExisteBD = Function('BaseDeDatos', 'return aspExisteBD(BaseDeDatos)');
    this.BaseDeDatosActual = Function('return aspBaseDeDatosActual()');
    this.DefineBD = Function('BaseDeDatos', 'return aspDefineBD(BaseDeDatos)');
    this.CreaVariable = Function('Contexto', 'Variable', 'return aspCreaVariable(Contexto, Variable)');
    this.ActualizaVariable = Function('Contexto', 'Variable', 'Valor', 'return aspActualizaVariable(Contexto, Variable, Valor)');
    this.ObtieneVariable = Function('Contexto', 'Variable', 'return aspObtieneVariable(Contexto, Variable)');
    this.EliminaVariable = Function('Contexto', 'Variable', 'return aspEliminaVariable(Contexto, Variable)');
    this.EliminaContexto = Function('Contexto', 'return aspEliminaContexto(Contexto)');
    this.ListaVariables = Function('Contexto', 'return aspListaVariables(Contexto)');
}

</script>

<script Id=ImplementacionDeLaInterfaseRS runat=server language="vbscript">

Public Function aspExisteBD(ByVal BaseDeDatos)
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    aspExisteBD = fso.FileExists(Server.MapPath("\yourserver\yourDBd irectory\" & BaseDeDatos & ".mdb"))
    Set fso = Nothing
End Function

Public Function aspBaseDeDatosActual()
    Dim rsVariables, BaseDeDatos
    Set rsVariables = CreateObject("ADODB.Recordset")
    rsVariables.Open "EXECUTE ObtieneVariable 'Aplicacion', 'BaseDeDatos'", dbConexion("Sistema")
    If Not (rsVariables.BOF And rsVariables.EOF) Then
     BaseDeDatos = rsVariables("Valor")
    Else
     BaseDeDatos = "«NO ESTA DEFINIDA»"
    End If
    rsVariables.Close
    Set rsVariables = Nothing
    aspBaseDeDatosActual = BaseDeDatos
End Function

Public Function aspDefineBD(ByVal BaseDeDatos)
    Dim Existe, rsVariables
    Existe = aspExisteBD(BaseDeDatos)
    If Existe Then
     Set rsVariables = CreateObject("ADODB.Recordset")
     rsVariables.Open "EXECUTE ObtieneVariable 'Aplicacion', 'BaseDeDatos'", dbConexion("Sistema")
     If (rsVariables.BOF And rsVariables.EOF) Then
        Existe = ExecutaComandoDB("Sistema", "CreaVariable 'Aplicacion', 'BaseDeDatos'", 1)
     End If
     If Existe Then
        Existe = ExecutaComandoDB("Sistema", "ActualizaVariable '" & BaseDeDatos & "', 'Aplicacion', 'BaseDeDatos'", 1)
     End If
     rsVariables.Close
     Set rsVariables = Nothing
    Else
     ExecutaComandoDB "Sistema", "ActualizaVariable NULL, 'Aplicacion', 'BaseDeDatos'", 1
    End If
    aspDefineBD = Existe
End Function

Public Function aspCreaVariable(ByVal Contexto, ByVal Variable)
    aspCreaVariable = ExecutaComandoDB("Sistema", "CreaVariable '" & Contexto & "', '" & Variable & "'", 1)
End Function

Public Function aspActualizaVariable(ByVal Contexto, ByVal Variable, ByVal Valor)
    aspActualizaVariable = ExecutaComandoDB("Sistema", "ActualizaVariable '" & Valor & "', '" & Contexto & "', '" & Variable

& "'", 1)
End Function

Public Function aspObtieneVariable(ByVal Contexto, ByVal Variable)
    Dim rsVariables
    Set rsVariables = CreateObject("ADODB.Recordset")
    rsVariables.Open "EXECUTE ObtieneVariable '" & Contexto & "', '" & Variable & "'", dbConexion("Sistema")
    aspObtieneVariable = rsVariables("Valor")
    rsVariables.Close
    Set rsVariables = Nothing
End Function

Public Function aspEliminaVariable(ByVal Contexto, ByVal Variable)
    aspEliminaVariable = ExecutaComandoDB("Sistema", "EliminaVariable '" & Contexto & "', '" & Variable & "'", Null)
End Function

Public Function aspEliminaContexto(ByVal Contexto)
    aspEliminaContexto = ExecutaComandoDB("Sistema", "EliminaContexto '" & Contexto & "'", Null)
End Function

Public Function aspListaVariables(ByVal Contexto)
    Dim CR, dbFiltro, rsVariables, rsXML, ContextoActual, CierraNodo
    CR = Chr(13): dbFiltro = "": CierraNodo = " </CONTEXTO>" & CR
    If Len(Contexto) > 0 Then
     dbFiltro = " WHERE (Contexto='" & Contexto & "')"
    End If
    Set rsVariables = CreateObject("ADODB.Recordset")
    rsVariables.Open "SELECT * FROM VariablesDeEstado" & dbFiltro & ";", dbConexion("Sistema")
    rsXML = _
     "<?xml version=""1.0""?>" & CR & _
     "<VARIABLES_DE_ESTADO>" & CR
    ContextoActual = ""
    With rsVariables
     If Not (.BOF And .EOF) Then
        Do While Not .EOF
         If (rsVariables("Contexto") <> ContextoActual) Then
            ContextoActual = rsVariables("Contexto")
            rsXML = rsXML & _
             " <CONTEXTO ID=""" & ContextoActual & """>" & CR
         End If
         rsXML = rsXML & _
            " <VARIABLE NOMBRE=""" & rsVariables("Variable") & """" & _
                                 " VALOR=""" & rsVariables("Valor") & """/>" & CR
         .MoveNext
         If .EOF Then
            rsXML = rsXML & CierraNodo
         Else
            If (rsVariables("Contexto") <> ContextoActual) Then
             rsXML = rsXML & CierraNodo
            End If
         End If
        Loop
     End If
     .Close
    End With
    rsXML = rsXML & "</VARIABLES_DE_ESTADO>" & CR
    Set rsVariables = Nothing
    aspListaVariables = rsXML
End Function

Private Function ExecutaComandoDB(ByVal BaseDeDatos, ByVal SQL, ByVal Afectados)
    Dim dbComando, Registros
    Set dbComando = CreateObject("ADODB.Command")
    With dbComando
     .ActiveConnection = dbConexion(BaseDeDatos)
     .CommandText = "EXECUTE " & SQL
     .Execute Registros, , adExecuteNoRecords
    End With
    Set dbComando = Nothing
    ExecutaComandoDB = IIf(IsNull(Afectados), (Registros > 0), (Registros = Afectados))
End Function

Private Function dbConexion(ByVal BaseDeDatos)
    ' ------------------------------------------------------------------------------------------------
    ' Change, in the DBQ parameter, «yourserver» to the names of your own configuration.
    ' ------------------------------------------------------------------------------------------------
    dbConexion = "DRIVER={Microsoft Access Driver (*.mdb)}; " & _
                         "DBQ=" & Server.MapPath("\yourserver\yourDBdirectory\" & BaseDeDatos & ".mdb")
End Function

Private Function IIf(ByVal bCondition, ByVal vTrueResult, ByVal vFalseResult)

    If bCondition Then
     IIf = vTrueResult
    Else
     IIf = vFalseResult
    End If

End Function

</script>

----------------------------------------------------------------------------------------------------------------------------

--------



<HTML>
<HEAD>
<TITLE>Sinergia XXI - Pruebas de Acceso Remoto - Derechos Reservados.</TITLE>
<META content="Microsoft Visual Studio" name=GENERATOR>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>


<SCRIPT language=JavaScript id=RSProxy>
RSEnableRemoteScripting("../_ScriptLibrary")
</SCRIPT>

<script id="controlDeLlamadasRS" language="javascript">

var insertaIslaXML = false;

function executaMetodoSincrono(Clase, Metodo, IslaXML)
{
var aspClaseRS = RSGetASPObject(Servidor + Clase);
var objMetodo = eval("aspClaseRS." + Metodo + ";");
return(objMetodo.return_value);
if (IslaXML)
    procesaIslaXML(objMetodo.return_value);
}

function executaMetodoAsincrono(Clase, Metodo, Contexto, IslaXML)
{
txtResultados.value = "Ejecutando llamada remota...";
insertaIslaXML = IslaXML;
var controlDeRespuesta = ", muestraResultadoRS, controlDeErroresRS, '"
var sinArgumentos = (Metodo.indexOf(")") - Metodo.indexOf("(") == 1)
Metodo = Metodo.substr(0, Metodo.indexOf(")")) + ((sinArgumentos) ? "''" : "");
var aspClaseRS = RSGetASPObject(Servidor + Clase);
var llamadaRS = "aspClaseRS." + Metodo + controlDeRespuesta + Contexto + "');";
var objMetodo = eval(llamadaRS);
}

function procesaIslaXML(Contexto, XML)
{
if (eval("(typeof(xml_" + Contexto + ") == 'object')"))
{
    eval("xml_" + Contexto + ".removeNode(true)");
}
XML = '<XML id="xml_' + Contexto + '">\r' + XML + '\r</XML>\r';
metodosRSDelCliente.insertAdjacentHTML("afterE nd", XML);
}

function verificaIslaXML(Contexto, Nodo)
{
var elementoXML;
if (eval("(typeof(xml_" + Contexto + ") == 'object')"))
{
    var objNodoXML = eval("xml_" + Contexto + ".XMLDocument.getElementsByTagName(Nodo);");
    var txtAviso = 'Se ha creado correctamente la isla XML para "' + Contexto + '":\r';
    txtAviso += "con los siguientes valores para " + Nodo + ":\r\r";
    for (var i = 0; i < objNodoXML.length; i++)
    {
     elementoXML = objNodoXML.item(i).text;
     txtAviso += "Nodo " + (i + 1) + ": " + ((elementoXML.indexOf("\r")) ? "" : "\r");
     txtAviso += elementoXML + "\r";
    }
    alert(txtAviso);
}
else
    alert('No exsiste Isla XML para: "' + Contexto + '"');
}

function muestraResultadoRS(objMetodo)
{
switch (objMetodo.context)
{
    default :
     txtResultados.value = objMetodo.return_value;
}
if (insertaIslaXML)
    procesaIslaXML(objMetodo.context, objMetodo.return_value);
}

function controlDeErroresRS(objMetodo)
{
switch (objMetodo.context)
{
    default :
     txtResultados.value = objMetodo.data;
}
}

</script>

<script language=vbscript id=clientEventHandlersVBS>
<!--

Public Const Servidor = "http://yourserver/"
Public Const ASPClaseVariables = "yourscriptsfolder/theASPfilename.asp" 'the above file

Sub btnExisteBD_onclick

Dim BaseDeDatos, Metodo
BaseDeDatos = InputBox("Introduzca el Nombre de la Base de Datos")
If Not IsBlank(BaseDeDatos) Then
    Metodo = "ExisteBD(""" & BaseDeDatos & """)"
    executaMetodoAsincrono ASPClaseBasesDeDatos, Metodo, "mtdExisteBD", false
End If

End Sub

Sub btnBaseDeDatosDefinida_onclick

Dim Metodo
Metodo = "BaseDeDatosActual()"
executaMetodoAsincrono ASPClaseBasesDeDatos, Metodo, "mtdBaseDeDatosActual", false

End Sub

Sub btnDefineBD_onclick

Dim BaseDeDatos, Metodo
BaseDeDatos = InputBox("Introduzca el Nombre de la Base de Datos")
If Not IsBlank(BaseDeDatos) Then
    Metodo = "DefineBD(""" & BaseDeDatos & """)"
    executaMetodoAsincrono ASPClaseBasesDeDatos, Metodo, "mtdBaseDeDatosActual", false
End If

End Sub

Sub btnCreaVariable_onclick

Dim Contexto, Variable, Metodo
Contexto = InputBox("Introduzca el Contexto de la Variable")
Variable = InputBox("Introduzca el Nombre de la Variable")
If Not (IsBlank(Contexto) Or IsBlank(Variable)) Then
    Metodo = "CreaVariable(""" & Contexto & """, """ & Variable & """)"
    executaMetodoAsincrono ASPClaseVariables, Metodo, "mtdCreaVariable", false
End If

End Sub

Sub btnActualizaVariable_onclick

Dim Contexto, Variable, Valor, Metodo
Contexto = InputBox("Introduzca el Contexto de la Variable")
Variable = InputBox("Introduzca el Nombre de la Variable")
Valor = InputBox("Introduzca el Valor a actualizar")
If Not (IsBlank(Contexto) Or IsBlank(Variable) Or IsBlank(Valor)) Then
    Metodo = "ActualizaVariable(""" & Contexto & """, """ & Variable & """, """ & Valor & """)"
    executaMetodoAsincrono ASPClaseVariables, Metodo, "mtdActualizaVariable", false
End If

End Sub

Sub btnObtieneVariable_onclick

Dim Contexto, Variable, Metodo
Contexto = InputBox("Introduzca el Contexto de la Variable")
Variable = InputBox("Introduzca el Nombre de la Variable")
If Not (IsBlank(Contexto) Or IsBlank(Variable)) Then
    Metodo = "ObtieneVariable(""" & Contexto & """, """ & Variable & """)"
    executaMetodoAsincrono ASPClaseVariables, Metodo, "mtdObtieneVariable", false
End If

End Sub

Sub btnEliminaVariable_onclick

Dim Contexto, Variable, Metodo
Contexto = InputBox("Introduzca el Contexto de la Variable")
Variable = InputBox("Introduzca el Nombre de la Variable")
If Not (IsBlank(Contexto) Or IsBlank(Variable)) Then
    Metodo = "EliminaVariable(""" & Contexto & """, """ & Variable & """)"
    executaMetodoAsincrono ASPClaseVariables, Metodo, "mtdEliminaVariable", false
End If

End Sub

Sub btnEliminaContexto_onclick

Dim Contexto, Metodo
Contexto = InputBox("Introduzca el Contexto")
If Not IsBlank(Contexto) Then
    Metodo = "EliminaContexto(""" & Contexto & """)"
    executaMetodoAsincrono ASPClaseVariables, Metodo, "mtdEliminaContexto", false
End If

End Sub

Sub btnListaVariables_onclick

Dim Contexto, Variable, Metodo
Contexto = InputBox("Introduzca el Contexto de la Variable")
Metodo = "ListaVariables(""" & Contexto & """)"
executaMetodoAsincrono ASPClaseVariables, Metodo, "mtdListaVariables", true

End Sub


-->
</script>


Prueba de despacho de métodos ASP Remotos de la Biblioteca VARIABLES.<br>


<TABLE>
<tr>
    <td>
     <p align=center>

         Métodos Remotos

     </p>
    </td>
    <td>
     <p align=center>

         Resultados enviados por el Servidor, vía el Remote Scripting Proxy

     </p>
    </td>
</tr>
<TR>
    <TD vAlign=top>
     <INPUT id=btnExisteBD style="WIDTH: 170px" type=button value="Existe Base De Datos"><BR>
     <INPUT id=btnBaseDeDatosActual style="WIDTH: 170px" type=button value="Base de Datos Actual"><BR>
     <INPUT id=btnDefineBD style="WIDTH: 170px" type=button value="Define Base De Datos"><BR>
     <INPUT id=btnCreaVariable style="WIDTH: 170px" type=button value="Crea Variable"><BR>
     <INPUT id=btnActualizaVariable style="WIDTH: 170px" type=button value="Actualiza Variable"><BR>
     <INPUT id=btnObtieneVariable style="WIDTH: 170px" type=button value="Obtiene Variable"><BR>
     <INPUT id=btnEliminaVariable style="WIDTH: 170px" type=button value="Elimina Variable"><BR>
     <INPUT id=btnEliminaContexto style="WIDTH: 170px" type=button value="EliminaContexto"><BR>
     <INPUT id=btnListaVariables style="WIDTH: 170px" type=button value="Lista Variables"><BR>
    </TD>
    <TD>
     <TEXTAREA id=txtResultados rows=20 cols=75>
         </TEXTAREA>
        </TD>
     </TR>
    </TABLE>
< br>


     <b>TODOS LOS DERECHOS © RESERVADOS 2003 - Carlos Bardullas Subirats; Minatitlán Nº 447, Col. Oriental Sur; Tel/Fax: 52
(312) 313-1343; Colima, Colima; México.</b>

</BODY>
</HTML>

Regards:
Carlos Bardullas Subirats





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 10:50 AM
file upload asudhakar C# 1 April 4th, 2007 07:29 AM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.