IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP Discussion :

Lire XML avec ASP


Sujet :

ASP

  1. #1
    Membre à l'essai
    Inscrit en
    Octobre 2003
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Octobre 2003
    Messages : 15
    Points : 15
    Points
    15
    Par défaut Lire XML avec ASP
    Bonjour,
    je cherche a lire en ASP une suite de produits qui arrive en XML de flash :
    <docXml>
    <divers>
    <bla>blabla</bla>
    <blo>bloblo</blo>
    </divers>
    <commande>
    <produit>
    <prodId>5 </prodId>
    <Qte>15</Qte>
    </produit>
    <produit>
    <prodId>2 </prodId>
    <Qte>12</Qte>
    </produit>
    </commande>
    <docXml>

    j'arrive a sortir les premiers elements (statique) mais
    je n'arrive pas a faire une boucle pour recupere pour les enregistrer dans une bdd les produits !!

    <%@ LANGUAGE="VBSCRIPT" CODEPAGE=65001 %>
    <%
    Dim xmlDoc, rootElement
    Dim blaNode, bla
    Dim bloNode, blo

    Dim prodIdNode, prodId
    Dim QteNode, Qte

    ' --- Get the XML parser ---
    Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

    ' --- Pull in the data from Flash ---
    xmlDoc.loadXML(Request.Form)

    ' --- Get the root element ---
    Set rootElement = xmlDoc.documentElement

    ' --- Get the blaNode ---
    Set blaNode = rootElement.FirstChild.selectSingleNode("bla")
    bla = blaNode.text

    ' --- Get the bloNode ---
    Set bloNode= rootElement.FirstChild.selectSingleNode("blo")
    blo= bloNode.text
    ....

    Comment faire la boucle pour recupere les X produits avec les infos Qte, ProdID . svp svp SVPPPP,
    je trouve des explications en ASP.net mais pas en ASP tout cours
    (3 jours que j'avance pas d'une ligne de code !)
    Merci Merci Merci ...
    @+
    Tops

    Note : je peut metre toute la pageASP et le code flash si ca peut aider ou servir.

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 166
    Points : 189
    Points
    189
    Par défaut
    Un bout de code que j'ai conservé qui pourra peut-être t'aider :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    function attribute_walk(node)
                    dim attrib
    	For Each attrib In node.attributes
    	   'type d'attribut
    	   Response.Write "///" & (attrib.nodeTypeString) & "///"
    	   'nom de l'attribut
    	   Response.Write(attrib.name)& "///"
    	   'valeur de l'attribut
    	   Response.Write(attrib.nodeValue)& "///<BR>"	 
    	Next
     
    end function
     
    'fonction determinant l'arborescence xml par récursivité
    function tree_walk(node)
    	dim nodeName
    	dim i
    	Dim child
    	'pour chaque enfant du noeud en cours
    	For Each child In node.childNodes
    	'type de contenu XML(processing,element,text,Comment,CDATA,EntityReference)
    	   Response.Write("**" & child.nodeTypeString) & "**"
     
    	   If child.nodeType<3 Then
    	   'on ne fait la description que des types(element(1),attribut(2))
    	   Response.Write("**" & child.nodeName & "**")
    	   End If
     
    	   If (child.nodeType=1) Then 
    		'si c'est un element
    		If (child.attributes.length>0) Then
    		's'il a des attributs:appel de la fonction les décrivant
    		  attribute_walk(child)
    		End If
                       End If
    	   If (child.hasChildNodes) Then
    	     's'il existe des noeuds enfants pour le noeud courant
    	     'continuer l'analyse des noeuds suivants en rapelant la 
    	     'fonction en cours
    	      tree_walk(child)
    	   Else
    	     'sinon contenu de balise(le texte)
    	     Response.Write "**" & child.text & "**"
    	     Response.Write("<br>")
    	   End If
                    Next
     
    end function

  3. #3
    Membre à l'essai
    Inscrit en
    Octobre 2003
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Octobre 2003
    Messages : 15
    Points : 15
    Points
    15
    Par défaut j'y plonge...
    ben y a déja de quoi avencer, c'est sur
    j'y plonge

    Merci a toi Amar00.

  4. #4
    Membre à l'essai
    Inscrit en
    Octobre 2003
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Octobre 2003
    Messages : 15
    Points : 15
    Points
    15
    Par défaut Re: j'y plonge...
    Voila le résultat
    y a mieux, mais ca marche déja

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    ' --- Insere la liste des produit dans T_CliCmdDetail ---
    ' --- envoie de reponce pour debugage --- Facultatif ---
    Dim reponce2_xml			'--- Facultatif ---
    reponce2_xml = "<reponce2_xml>"	'--- Facultatif ---
     
    Dim NodeEnfant
    For Each NodeEnfant In testNode.childNodes
    	Dim enfantNode
    	Dim ProdId
    	dim ProdLibele
    	Dim QteCom
    	Dim PrixHt
    	Dim idSession
     
    	enfantNode = NodeEnfant.FirstChild.nodeValue
    	ProdId = NodeEnfant.FirstChild.text
    	ProdLibele = NodeEnfant.FirstChild.NextSibling.text
    	QteCom = NodeEnfant.FirstChild.NextSibling.NextSibling.text
    	PrixHt = NodeEnfant.FirstChild.NextSibling.NextSibling.NextSibling.text
    	idSession = NodeEnfant.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.text
     
    	'--- Facultatif ---
    	reponce2_xml = reponce2_xml & "<enfantNode>" & enfantNode & "</enfantNode>"& "<ProdId>" & ProdId & "</ProdId>"& "<ProdLibele>" & ProdLibele & "</ProdLibele>"& "<QteCom>" & QteCom & "</QteCom>"&"<PrixHt>" & PrixHt & "</PrixHt>"&"<idSession>" & idSession & "</idSession>"
     
    	' --- requette insert ---
    	requeteStr = "insert into t_cliCmdDetail (CliCmdDetCliCmdId,CliCmdDetprodid,CliCmdDetprodlibelle,CliCmdDetQte,CliCmdDetPuHt,CliCmdDetidsession)"&_
    	"values ( '" & cliCmdId & "','" & prodId & "','" & ProdLibele & "','" & qteCom & "',convert(float(2),"&prixHt&"),'" & idSession & "')  "
    	' --- execute la requette ---
    	connection.execute requeteStr
    Next
    '--- Facultatif ---
    reponce2_xml = reponce2_xml + "</reponce2_xml>"
    ' --- Fin Insertion Produit ---
    Merci merci

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    166
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 166
    Points : 189
    Points
    189
    Par défaut
    Il y a plus cours en effet, voire la méthode qui s'applique un objet node :
    c'est un peu moins lourd que nextsibling().
    Un exemple ici : http://www.devguru.com/Technologies/...ingleNode.html

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Extraire Xml avec ASP
    Par croco83 dans le forum ASP
    Réponses: 0
    Dernier message: 06/08/2008, 12h40
  2. Manipulation XML avec ASP
    Par loic.keysoft dans le forum ASP
    Réponses: 4
    Dernier message: 16/05/2008, 16h46
  3. lire xml avec attributs dans balises
    Par cd090580 dans le forum Windows Forms
    Réponses: 6
    Dernier message: 08/01/2008, 19h27
  4. [AJAX] envoie XML avec ASP
    Par grosecret dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 24/05/2007, 11h06
  5. Creation d'un fichier XML avec ASP encoder en UTF-8
    Par freeze_land dans le forum ASP
    Réponses: 6
    Dernier message: 14/02/2007, 10h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo