Modificar datos XML

11/08/2005 - 14:34 por dalbo | Informe spam
Hola,
tengo unos datos en XMl, y accedo a los datos y los muestro a traves de la
correspondiente pagina web. Lo que ahora quiero hacer es poder modificar esos
datos desde la web. Sin tener que habrir el archivo XML y modificarlo.
Si alguien sabe como se puede hacer o donde puedo mirar para hacerlo le
estaria muy agradecido.
Gracias de antemano.

Preguntas similare

Leer las respuestas

#1 Rodrigo Fraga
25/10/2005 - 19:03 | Informe spam
Hola:
Supongo que te refieres a actualizar tu XML sin necesidad de hacerlo manual,
pues para actualizarlo es necesario abrir el archivo modificarlo y luego
cerrarlo.
Bueno hay opciones, usando tecnologías de Microsoft sería algo así:
Hacer una pagina web admin.asp o .aspx
<table>
<tr>
<td>
<table>
<tr>
<td>PartID:</td>
<td>
<asp:Label id="lblPartID"
runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="right"><asp:Label id="Label2"
runat="server">
Quantity: </asp:Label></td>
<td>
<asp:DropDownList id="ddlQuantity" runat="server">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td align="right"><asp:Label id="Label1"
runat="server">
Color: </asp:Label></td>
<td>
<asp:DropDownList id="ddlColors" runat="server">
<asp:ListItem Value="White"
White</asp:ListItem>


<asp:ListItem
Value="Black">Black</asp:ListItem>
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td align="right"><asp:Label id="Label3"
runat="server">
Manufacturer: </asp:Label></td>
<td>
<asp:DropDownList id="ddlManufacturer"
runat="server">
<asp:ListItem
Selected="True">Torux</asp:ListItem>
<asp:ListItem>Pear</asp:ListItem>
<asp:ListItem>MacroWare</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td align="right"><asp:Label id="Label4"
runat="server">
Price: </asp:Label></td>
<td>
<asp:DropDownList id="ddlPrice" runat="server">
<asp:ListItem Value="1" >1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="2">
<asp:Button id="btnUpdate" runat="server"
Text="Update"></asp:Button></td>
</tr>
</table>
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</td>
</tr>
</table>

Luego incluir el siguiente código en VB
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
'Get Data
Dim ds As New DataSet()
ds.ReadXml(Server.MapPath(".") & "\..\Xml\PartList.xml")
lblPartID.Text = CType(ds.Tables(0).Rows(0).Item("PartID"),
String)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
ds.Dispose()
End If

End Sub

Private Sub btnUpdate_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim ds As New DataSet()
Try
'Refill the dataset
ds.ReadXml(Server.MapPath(".") & "\..\Xml\PartList.xml")
'Make the Updates
ds.Tables(0).Rows(0).Item("PartID") = lblPartID.Text
ds.Tables(0).Rows(0).Item("Quantity") =
ddlQuantity.SelectedItem.Text
ds.Tables(0).Rows(0).Item("Color") = ddlColors.SelectedItem.Text
ds.Tables(0).Rows(0).Item("Manufacturer") =
ddlManufacturer.SelectedItem.Text
ds.Tables(0).Rows(0).Item("Price") = ddlPrice.SelectedItem.Text
'Write the updated dataset as an xml file.
ds.WriteXml(Server.MapPath(".") & "\..\Xml\PartList.xml", _
XmlWriteMode.WriteSchema)
'Display the updated data in the Datagrid
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Catch
'Redirect to Error Page or take other action to handle error.
Finally
ds.Dispose()
End Try
End Sub

Ahora bien ASP o ASP.NET no son la unica solución puedes intentarlo usando
Javascript o PHP. pero creo que con esto puedes darte una idea de como
hacerlo.
Respuesta Responder a este mensaje
#2 Rodrigo Fraga
25/10/2005 - 19:10 | Informe spam
Hola de nuevo, me sentí por mal por no darte otra opción mas, asi que te
adjunto una alternativa en Javascript.
En el HTML
<script for="window" event="onLoad">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("archivo.xml");
nodes=xmlDoc.documentElement.childNodes;
</script>
<script>
function submitform(){
var fso=new ActiveXObject("Server.FileSystemObject");
var xml=fso.openTextFile("archivo.xml");
}
</script>
El XML
<?xml version="1.0" encoding="Windows-1252" ?>
<MESSAGE>
<USER>Administrator</USER>
<COMMENT>Welcome to this message board!</COMMENT>
</MESSAGE>

Nota que la actualización se hará desde un formulario que una vez llenado se
envia la información, llama a la función de java submitform(); abre el xml y
coloca los datos enviados; es probable que no funcione correctamente este
ejemplo pero te da una idea de como hacerlo =P
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida