1 Reply Latest reply on Apr 16, 2007 11:23 PM by Newsgroup_User

    FLASH + XML + ASP Problem

    MisguidedMortal
      Good afternoon everyone:

      I seem to be having some problems with Flash 8 reading an xml file generated by an .asp.

      Here is the ASP Code;

      Dim objCn, objRs, objCm, strXML

      Response.Buffer = true
      Set objCn = Server.CreateObject("ADODB.Connection")
      If Connect(objCn) Then
      Set objCm = Server.CreateObject("ADODB.Command")
      objCm.ActiveConnection = objCn
      objCm.CommandType = &H0004
      objCm.CommandText = "spCandidates"
      Set objRs = objCm.Execute
      objCm.ActiveConnection = Nothing
      Response.ContentType = "text/xml"
      strXML = "<?xml version=""1.0"" encoding=""ISO-8859-1""?><candidates>"
      Do While Not objRs.EOF
      If Len(objRs.Fields("SecondName")) > 0 Then
      strXML = strXML & "<candidate><id>" & CStr(objRs.Fields("idCandidate")) & "</id><name>" & objRs.Fields("FirstName") & _
      "</name><secondname>" & objRs.Fields("SecondName") & "</secondname><lastname>" & objRs.Fields("LastName") & "</lastname></candidate>"
      Else
      strXML = strXML & "<candidate><id>" & CStr(objRs.Fields("idCandidate")) & "</id><name>" & objRs.Fields("FirstName") & _
      "</name><secondname /><lastname>" & objRs.Fields("LastName") & "</lastname></candidate>"
      End If
      objRs.MoveNext
      Loop
      Call DisconnectIII(objCn, objRs, objCm)
      strXML = strXML & "</candidates>"
      Response.Write(strXML)
      Else
      Response.Write("Could not connect to Database.")
      Set objCn = Nothing
      End If

      This generates the xml file:

      <candidates>

      <candidate>
      <id>8</id>
      <name>Juan</name>
      <secondname>Alberto</secondname>
      <lastname>Cruz</lastname>
      </candidate>

      <candidate>
      <id>7</id>
      <name>John</name>
      <secondname>William</secondname>
      <lastname>Doe</lastname>
      </candidate>
      </candidates>

      the flash code is as follows:

      /*******************EVENT CODE *********************************/

      function clicked(){
      var myXML:XML = new XML();

      myXML.ignoreWhite = true;
      if (optOnline.selected){
      myXML.load("../asp/candidatenames.asp"); //FOR SOME REASON AN .xml WITH THE SAME STRUCTURE IS READ PERFECTLY
      }else{
      myXML.load("../asp/downloadcandidates.asp");
      }
      myXML.onLoad = function(success:Boolean){
      if (success){
      trace(myXML.status); //THIS GENERATES A -6 VALUE (A MALFORMED XML FILE)
      loadCandidates(myXML);
      }else{
      trace("unable to load XML");
      }
      }
      }
      btnLoad.addEventListener("click", clicked);

      /********************FUNCTIONS ***************************/

      function loadCandidates(myXML:XML):Void{
      var xmlNode:XMLNode;
      var intIdCandidate:Number = 0;
      var strCandidateLabel:String = "";

      xmlNode = myXML.firstChild.firstChild;
      trace(myXML);
      while (xmlNode != null){
      if (xmlNode.childNodes[2].firstChild.nodeValue != undefined){
      strCandidateLabel = xmlNode.childNodes[3].firstChild.nodeValue + ", " + xmlNode.childNodes[1].firstChild.nodeValue + " " + xmlNode.childNodes[2].firstChild.nodeValue;
      }else{
      strCandidateLabel = xmlNode.childNodes[3].firstChild.nodeValue + ", " + xmlNode.childNodes[1].firstChild.nodeValue;
      }
      cboNameList.addItem(strCandidateLabel, xmlNode.childNodes[0].firstChild.nodeValue);
      xmlNode = xmlNode.nextSibling;
      }
      }

      The problem is, that it doesn't seem to be able to read the xml information well, but if I use an .xml file directly, this works perfectly fine.

      What can be the problem?

      Thank you in Advance.
        • 1. Re: FLASH + XML + ASP Problem
          Level 7
          didn't go through all your code, but what caught my eyes was this line -
          strXML = "<?xml version=""1.0"" encoding=""ISO-8859-1""?><candidates>"

          first i'd try to change the encoding (i use UTF-8), and second - i'm not too
          expert in asp, but there's seem to be too many " signs there - how about
          '...version=\"1.0\" encoding=\"ISO-8859-1\"?>'

          eRez
          www.cinabu.com

          "MisguidedMortal" <webforumsuser@macromedia.com> wrote in message
          news:f00ulj$6pn$1@forums.macromedia.com...
          > Good afternoon everyone:
          >
          > I seem to be having some problems with Flash 8 reading an xml file
          > generated
          > by an .asp.
          >
          > Here is the ASP Code;
          >
          > Dim objCn, objRs, objCm, strXML
          >
          > Response.Buffer = true
          > Set objCn = Server.CreateObject("ADODB.Connection")
          > If Connect(objCn) Then
          > Set objCm = Server.CreateObject("ADODB.Command")
          > objCm.ActiveConnection = objCn
          > objCm.CommandType = &H0004
          > objCm.CommandText = "spCandidates"
          > Set objRs = objCm.Execute
          > objCm.ActiveConnection = Nothing
          > Response.ContentType = "text/xml"
          > strXML = "<?xml version=""1.0"" encoding=""ISO-8859-1""?><candidates>"
          > Do While Not objRs.EOF
          > If Len(objRs.Fields("SecondName")) > 0 Then
          > strXML = strXML & "<candidate><id>" & CStr(objRs.Fields("idCandidate")) &
          > "</id><name>" & objRs.Fields("FirstName") & _
          > "</name><secondname>" & objRs.Fields("SecondName") &
          > "</secondname><lastname>" & objRs.Fields("LastName") &
          > "</lastname></candidate>"
          > Else
          > strXML = strXML & "<candidate><id>" & CStr(objRs.Fields("idCandidate")) &
          > "</id><name>" & objRs.Fields("FirstName") & _
          > "</name><secondname /><lastname>" & objRs.Fields("LastName") &
          > "</lastname></candidate>"
          > End If
          > objRs.MoveNext
          > Loop
          > Call DisconnectIII(objCn, objRs, objCm)
          > strXML = strXML & "</candidates>"
          > Response.Write(strXML)
          > Else
          > Response.Write("Could not connect to Database.")
          > Set objCn = Nothing
          > End If
          >
          > This generates the xml file:
          >
          > <candidates>
          > ?
          > <candidate>
          > <id>8</id>
          > <name>Juan</name>
          > <secondname>Alberto</secondname>
          > <lastname>Cruz</lastname>
          > </candidate>
          > ?
          > <candidate>
          > <id>7</id>
          > <name>John</name>
          > <secondname>William</secondname>
          > <lastname>Doe</lastname>
          > </candidate>
          > </candidates>
          >
          > the flash code is as follows:
          >
          > /*******************EVENT CODE *********************************/
          >
          > function clicked(){
          > var myXML:XML = new XML();
          >
          > myXML.ignoreWhite = true;
          > if (optOnline.selected){
          > myXML.load("../asp/candidatenames.asp"); //FOR SOME REASON AN .xml WITH
          > THE
          > SAME STRUCTURE IS READ PERFECTLY
          > }else{
          > myXML.load("../asp/downloadcandidates.asp");
          > }
          > myXML.onLoad = function(success:Boolean){
          > if (success){
          > trace(myXML.status); //THIS GENERATES A -6 VALUE (A MALFORMED XML FILE)
          > loadCandidates(myXML);
          > }else{
          > trace("unable to load XML");
          > }
          > }
          > }
          > btnLoad.addEventListener("click", clicked);
          >
          > /********************FUNCTIONS ***************************/
          >
          > function loadCandidates(myXML:XML):Void{
          > var xmlNode:XMLNode;
          > var intIdCandidate:Number = 0;
          > var strCandidateLabel:String = "";
          >
          > xmlNode = myXML.firstChild.firstChild;
          > trace(myXML);
          > while (xmlNode != null){
          > if (xmlNode.childNodes[2].firstChild.nodeValue != undefined){
          > strCandidateLabel = xmlNode.childNodes[3].firstChild.nodeValue + ", " +
          > xmlNode.childNodes[1].firstChild.nodeValue + " " +
          > xmlNode.childNodes[2].firstChild.nodeValue;
          > }else{
          > strCandidateLabel = xmlNode.childNodes[3].firstChild.nodeValue + ", " +
          > xmlNode.childNodes[1].firstChild.nodeValue;
          > }
          > cboNameList.addItem(strCandidateLabel,
          > xmlNode.childNodes[0].firstChild.nodeValue);
          > xmlNode = xmlNode.nextSibling;
          > }
          > }
          >
          > The problem is, that it doesn't seem to be able to read the xml
          > information
          > well, but if I use an .xml file directly, this works perfectly fine.
          >
          > What can be the problem?
          >
          > Thank you in Advance.
          >
          >