Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Langages serveur > ASP
ASP Forum sur la programmation ASP. Avant de poster : Cours ASP, FAQ ASP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 15/05/2007, 18h44   #1
Nouveau Membre du Club
 
Inscription : novembre 2005
Messages : 317
Détails du profil
Informations forums :
Inscription : novembre 2005
Messages : 317
Points : 35
Points : 35
Par défaut Générer un fichier XML

Bonsoir,

J'aimerai savoir comment créer une page XML sur un serveur, à partir d'une page ASP ?

Le type de page XML que j'aimerai obtenir est comme cela :

Code :
1
2
3
4
5
6
7
8
9
10
 
<?xml version="1.0"?>
<Calander>
<info>
<Data date="2007-05-18">Info 1</Data>
</info>
<info>
<Data date="2007-05-23">Info 2</Data>
</info>
</Calander>
Avec ce type d'élément.

Merci de votre aide,

Denis
delavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/05/2007, 13h30   #2
Membre éprouvé
 
Avatar de malbaladejo
 
Inscription : avril 2002
Messages : 377
Détails du profil
Informations personnelles :
Âge : 34
Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

Informations forums :
Inscription : avril 2002
Messages : 377
Points : 477
Points : 477
Tu peux faire ceci:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
<%
Response.AddHeader "Content-Type","text/xml"
%>
 
<?xml version="1.0"?>
<Calander>
<info>
<Data date="<%=date1%>"><%=Info1%></Data>
</info>
<info>
<Data date="<%=date2%>"><%=Info2%></Data>
</info>
</Calander>
malbaladejo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/05/2007, 22h15   #3
Nouveau Membre du Club
 
Inscription : novembre 2005
Messages : 317
Détails du profil
Informations forums :
Inscription : novembre 2005
Messages : 317
Points : 35
Points : 35
Par défaut code correspondant mieux à mes besoins

Re,

Ce code correspondrait mieux à ce que j'ai besoin puisqu'il fait appel à une base de données, mais lorsque je fais l'essai en ligne, je n'obtiens rien au niveau du fichier xml crée :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
<%
'
 
Set conn = Server.CreateObject("ADODB.Connection")
connstring="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("./data/voyance.mdb")
conn.Open connstring
 
'
SQL = "SELECT * FROM events"
Set prod = Server.CreateObject("ADODB.Recordset")
prod.Open sql, conn, 3, 3
'
if not(prod.eof) then
 
'
'response.write("<?xml version="""1.0""" ?>")"
response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
 
response.write("<calander>")
'
do while not prod.EOF
'
response.write("<info>")
response.Write("<Url date=""" & prod.fields("date") & """ URL=""" & prod.fields("url") & """ />" )
response.write("</info>")
'
prod.MoveNext
Loop 
end if
'
response.write("</calander>")
'
Set xmlDoc = server.CreateObject("Microsoft.XMLDOM")
xmlDoc.preserveWhiteSpace=true
xmlDoc.Save "C:\customer.xml"
%>
delavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 16/05/2007, 22h40   #4
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
Pour générer un fichier XML il faut utiliser
Code :
server.CreateObject("Microsoft.XMLDOM")
Des response.write ne marchent pas
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/05/2007, 19h01   #5
Nouveau Membre du Club
 
Inscription : novembre 2005
Messages : 317
Détails du profil
Informations forums :
Inscription : novembre 2005
Messages : 317
Points : 35
Points : 35
Voici mon code, modifié avec informations que tu m'a donné :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
<%
'
 Dim objDom
 Dim objRoot
 Dim objField
 Dim objFieldValue
 Dim objattID
 Dim objattID2
 Dim objUrl
 
Set conn = Server.CreateObject("ADODB.Connection")
connstring="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("./data/voyance.mdb")
conn.Open connstring
 
'
SQL = "SELECT * FROM events"
Set prod = Server.CreateObject("ADODB.Recordset")
prod.Open sql, conn, 3, 3
'
if not(prod.eof) then
 
'Instantiate the Microsoft XMLDOM.
 Set objDom = server.CreateObject("Microsoft.XMLDOM")
 objDom.preserveWhiteSpace = True
 
 
 'Create your root element and append it to the XML document.
 Set objRoot = objDom.createElement("Calander")
 objDom.appendChild objRoot
'
do while not prod.EOF
'
Set objField = objDom.createElement("info")
Set objUrl = objDom.createElement("Data")
Set objattID = objDom.createAttribute("date")
objattID.Text = prod.fields("date")
Set objattID2 = objDom.createAttribute("date")
objattID2.Text = prod.fields("url")
objUrl.setAttributeNode objattID2
objUrl.setAttributeNode objattID
 
'Append the field element as a child of the root element.
objRoot.appendChild objField 
objField.appendChild objUrl
'
prod.MoveNext
Loop 
end if
'
'Create the xml processing instruction.
 Set objPI = objDom.createProcessingInstruction("xml", "version='1.0' encoding='UTF-8' ")
 
 'Append the processing instruction to the XML document.
 objDom.insertBefore objPI, objDom.childNodes(0)
 
 
 'Save the XML document.
 objDom.save "C:\denague_date.xml"
 
 
 'Release all of your object references.
 Set objDom = Nothing
 Set objRoot = Nothing
 Set objField = Nothing
 Set objUrl = Nothing
 Set objattID = Nothing
 Set objattID2 = Nothing
 Set objPI = Nothing
 
%>
Qui me rend en code XML ceci :

Code :
1
2
3
4
5
6
7
8
9
10
 
<?xml version="1.0" encoding="UTF-8"?>
<Calander>
<info>
<Data date="12/05/2007"/>
</info>
<info>
<Data date="14/06/2007"/>
</info>
</Calander>
Alors que je cherche à obtenir ce type de document XML :

Code :
1
2
3
4
5
6
7
8
9
10
 
<?xml version="1.0"?>
<Calander>
<info>
<Data date="2007-05-18">Info 1</Data>
</info>
<info>
<Data date="2007-05-23">Info 2</Data>
</info>
</Calander>
Si quelqu'un peu m'aider sur la modif du code asp que j'ai pour obtenir le résultat que je recherche ? merci

Denis
delavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/05/2007, 00h40   #6
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
Bon, j'espere que j'ai bien tout compris.
Avec ceci ça devrait aller un peu mieux sauf que cela n'ajoute pas d'attributs. Copie colle la totalité dans une page blanche et remplace simplement la requete SQL. Precise aussi correctement le chemin vers la base de données.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<%@ LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%Option explicit%>
 
<%
Dim strProvider 'Connection string
 
call main
 
sub main()
	call connect
	call XMLLauncher
end sub
 
Sub connect()
	'Connects to the Access driver and Access database in the Inetpub directory where the database is saved
	strProvider = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\CHEMIN VERS LA BASE;"
end sub
 
sub XMLLauncher
	dim rs, strqry, i
	set rs = server.CreateObject("adodb.recordset")
		strqry = "SELECT * FROM EAC_Dwnl;"
		rs.open strqry, strprovider, 1, 1
			response.Redirect(ConvertRStoXML(rs, "Noeud1", "Noeud2")) 
		rs.close
	set rs = nothing
end sub
 
function folderpath()
	Dim fs,f
	Set fs = Server.CreateObject("Scripting.FileSystemObject")
		Set f = fs.GetFile(request.ServerVariables("PATH_TRANSLATED"))
			folderpath = replace(request.ServerVariables("PATH_TRANSLATED"), f.name,"")
		set f = nothing
	set fs = nothing
end function
 
Function ConvertRStoXML(objRS, strTopLevelNodeName, strRowNodeName)
	on error resume next
 
	Dim objDom
	Dim objRoot
	Dim objField
	Dim objFieldValue
	Dim objcolName
	Dim objattTabOrder
	Dim objPI
	Dim x
	Dim objRSField
	Dim objRow
	Dim filename
 
	objRS.movefirst
 
	'Instantiate the Microsoft XMLDOM.
	Set objDom = server.CreateObject("Microsoft.XMLDOM")
	objDom.preserveWhiteSpace = True
 
	'Create your root element and append it to the XML document.
	Set objRoot = objDom.createElement(strTopLevelNodeName)
	objDom.appendChild objRoot
 
	Do While Not objRS.EOF
		Set objRow = objDom.CreateElement(strRowNodeName)
 
		For Each objRSField in objRS.Fields
			Set objField = objDom.createElement(objRSField.Name)
			objField.Text = objRSField.Value
 
			objField.appendChild objFieldValue
 
			objRow.appendChild objField
		Next 
 
		objRoot.appendChild objRow
 
		objRS.MoveNext
	Loop
 
	Set objPI = objDom.createProcessingInstruction("xml", "version='1.0' encoding='iso-8859-1'")
	objDom.insertBefore objPI, objDom.childNodes(0)
 
	filename = "test.xml"
	objDom.Save folderpath() & filename
	ConvertRStoXML = filename
 
	'Clean up...
	Set filename = nothing
	Set objDom = Nothing
	Set objRoot = Nothing
	Set objField = Nothing
	Set objFieldValue = Nothing
	Set objcolName = Nothing
	Set objattTabOrder = Nothing
	Set objPI = Nothing
End Function
 
%>
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/05/2007, 15h00   #7
Membre actif
 
Avatar de lapanne
 
Inscription : juin 2006
Messages : 200
Détails du profil
Informations forums :
Inscription : juin 2006
Messages : 200
Points : 168
Points : 168
Envoyer un message via MSN à lapanne
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Response.ContentType = "text/html"
Response.AddHeader "Content-Disposition","attachment; filename=Annuaire.xml"
 
Response.Write "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbCrLf & "<annuaire>" & vbCrLf
 
'--------------------------------
Set Utilisateurs = Server.CreateObject("ADODB.Connection")
Utilisateurs.Open Session("Annuaire_ConnectionString"), Session("Utilisateurs_RuntimeUserName"), Session("Utilisateurs_RuntimePassword")
Set cmdTemp = Server.CreateObject("ADODB.Command")
Set RSLst = Server.CreateObject("ADODB.Recordset")
cmdTemp.CommandText = "dbo.SP_xxxxx"
cmdTemp.CommandType = 4
cmdTemp.ActiveConnection = Utilisateurs
RSLst.CursorType = 0
RSLst.LockType = 1
RSLst.Open(cmdTemp)
 
Response.Flush
While Not RSLst.EOF
		Response.Write "<personne>" & vbCrLf
		Response.Write "	<matricule>" & RSLst("id_pandore") & "</matricule>" & vbCrLf
		Response.Write "  <nom>" & RSLst("nom") & "</nom>" & vbCrLf
		Response.Write "  <prenom>" & RSLst("prenom") & "</prenom>" & vbCrLf
		Response.Write "  <tel>" & RSLst("telephone") & "</tel>" & vbCrLf
		Response.Write "  <extension>" & RSLst("extension_tel") & "</extension>" & vbCrLf
		Response.Write "  <fax>" & RSLst("fax") & "</fax>" & vbCrLf
		Response.Write "  <mobile>" & RSLst("mobile") & "</mobile>" & vbCrLf
		Response.Write "  <mail>" & RSLst("mail_fast") & "</mail>" & vbCrLf
		Response.Write "</personne>" & vbCrLf
		RSLst.MoveNext
Wend
Response.Write "</annuaire>"
Si ça peut t'aider voici une page asp de génération d'un fichier XML.
__________________
<SplyRock95> c'est quoi ton style?
<Bat> #bat{height:180cm;weight:160lbs; eye-color:#0000FF; hair-color: #FFFF00;}
Copyright @ bashfr.org
lapanne est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/05/2007, 16h48   #8
Nouveau Membre du Club
 
Inscription : novembre 2005
Messages : 317
Détails du profil
Informations forums :
Inscription : novembre 2005
Messages : 317
Points : 35
Points : 35
Par défaut version minimal sortie xml dans page asp

Bonsoir,

J'utilise le code ci-dessous, pour avoir une des informations de type XML dans ma page asp :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-utf8-1">
<title>Document sans nom</title>
</head>
<body>
<%
'
'connection à la base de données
Set oC = Server.CreateObject("ADODB.Connection")
oC.Provider = "Microsoft.Jet.OLEDB.4.0"
oC.Open "Data Source=" & Server.MapPath("./data/voyance.mdb") 
'sélectionne toute les nouvelles
SQL ="SELECT * FROM events"
 
'création du Recordset
Set oRS = CreateObject("ADODB.Recordset")
oRS.Open SQL,oC,3,3
 
'création du document XML  
response.write "<?xml version=""1.0"" ?>"
response.write("<Calander>")
 
' boucle pour collecter toutes les nouvelles
ors.movefirst
do while not ors.eof
response.write("<info>")
response.Write "<Data date=""" & ors("date") & """>" & ors("url") & "</Data>"
 
response.write("</info>")
ors.movenext
 
Loop
 
'on ferme le document XML
response.write("</Calander> ")
 
'on ferme la connection à la bdd
Set oRS = Nothing
oC.Close
Set oC = Nothing
%>  
 
</body>
</html>
Ce qui me donne en sortie, lorsque j'affiche la source de ma page :

Code :
1
2
3
4
5
6
7
8
9
10
11
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-utf8-1">
<title>Document sans nom</title>
</head>
<body>
<?xml version="1.0" ?><Calander><info><Data date="2007-05-18">denague.com</Data></info><info><Data date="2007-06-02">papy.com</Data></info></Calander>   
 
</body>
</html>
Est-ce que c la version minimale de la sortie XML ? C'est à dire que j'aimerai, lorsque j' affiche la source de la page, ne plus avoir de code HTML, est-ce que cela est possible ?

Merci d'avance,

Denis
delavega est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/05/2007, 09h20   #9
Modérateur
 
Avatar de roro06
 
Inscription : avril 2007
Messages : 1 364
Détails du profil
Informations personnelles :
Âge : 42

Informations forums :
Inscription : avril 2007
Messages : 1 364
Points : 1 551
Points : 1 551
Bonjour

Tu dois d'abord enlever toutes les balises HTML, surtout celle-ci :
<meta http-equiv="Content-Type" content="text/html; charset=iso-utf8-1">

Puis rajouter en début de script :
response.ContentType="text/XML"

Ce faisant, n'en déplaise à immobilis, des response.write suffisent amplement

cordialement
roro06 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/05/2007, 09h38   #10
Expert Confirmé Sénior

 
Avatar de Immobilis
 
Inscription : mars 2004
Messages : 5 849
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 5 849
Points : 5 965
Points : 5 965
Citation:
Envoyé par roro06
Ce faisant, n'en déplaise à immobilis, des response.write suffisent amplement
Pas de soucis
Immobilis est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h45.


 
 
 
 
Partenaires

Hébergement Web