Accedere ad un attributo di un file XML con XMLDOM ed ASP | |
![]() |
|
| |
|
ASP Center
Articoli
Referenze
Script
FAQ
Downloads
Siti utili
ASP
E-Commerce con ASP
Menu Javascript
Area Aziende
Cocktail
Registrazione domini
|
Accedere ad un attributo di un file XML con XMLDOM ed ASP
Abbiamo visto in più riprese come compiere tutte le principali operazioni di lettura e scrittura su e da un file XML con l'oggetto XMLDOM ed ASP. Vediamo adesso come acceder ad un attributo.
Negli scorsi articoli abbiamo aggiunto un attributo alla struttura del già noto file XML di esempio "rubrica.xml" di cui ripropongo la struttura
<?xml version="1.0" encoding="ISO-8859-1"?>
<rubrica>
<utente>
<nome id="1">Pippo</nome>
<telefono>001122</telefono>
</utente>
<utente>
<nome id="2">Pluto</nome>
<telefono>334455</telefono>
</utente>
<utente>
<nome id="3">Paperino</nome>
<telefono>667788</telefono>
</utente>
<utente>
<nome id="4">Minnie</nome>
<telefono>990011</telefono>
</utente>
</rubrica>
In funzione di questa struttura XML vediamo come accedere all'attributo "id". Segue un esempio di codice
<html>
<body>
<%
Dim MyXML
Set MyXML = Server.CreateObject("Microsoft.XMLDOM")
MyXML.Async = False
MyXML.Load Server.MapPath("rubrica.xml")
Dim id
Set id = MyXML.getElementsByTagName("utente/nome")
Dim i
i = 0
For i = 0 To id.length - 1
Response.Write id(i).getAttribute("id") & "<br>"
Next
Set nome = Nothing
Set telefono = Nothing
Set MyXML = Nothing
%>
</body>
</html>
Utilizziamo semplicemente il metodo getAttribute a cui passiamo come parametro il nome dell'attributo che ci interessa esplorare.Il risultato dello script sarà semplicemente 1 2 3 4 |
Newsletter
Stringhe di Conn.
|
||
| © 2008 ASP Center di Luca Ruggiero - P. IVA 05564851219 - Disclaimer | Privacy | Pubblicità | Supportaci | Staff | Contatti | ||||
| Appunti PHP | Giornale Webmaster | Mr.Webmaster | Download | DevSpy.com | ASPCode.it | ClaudioGarau.it | Webmaster Facile | Come Faccio | AlVerde.net | CodiceFacile.it | I Programmatori | By Luciani | VoiceXML Italian User Group | Giochi | Extro Web Site | Morpheus Web | AG Web Solutions | Net-Free | PC Sicuro | PC Self | Tutorial Web | Dablones | ||||