#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    410
    Rep Power
    19

    Question XML and Javascript


    Hi all,

    I have a problem of handling XML and Javascript. I have a webpage of using javascript to call data from another server in form of XML. The HTML code is like that

    <html>
    <script language="javascript">

    function displayMeaning(XMLObject) {
    var tmpNode = XMLObject.getElementsByTagName("data");
    var meaningTXT = tmpNode.nextNode().text;
    meaning.value += meaningTXT;
    }

    function checkDic() {
    meaning.value = "Enquiry......";
    checkMeaning.load('/webstat/xmlreport.pl');
    }

    </script>
    <body>
    <textarea name="meaning" class="tableTitle" rows=10 cols=50 readonly=true>
    </textarea>
    <XML id="checkMeaning" src="" ondatasetcomplete="displayMeaning(this)"></XML>
    <input type="button" name="cmdEnquiry" value="Enquiry" onClick="checkDic();">
    </body>
    </html>

    But this code can get ONE tag data only
    for example, if the retrieved XML is
    <? xml ?>
    <data>Hello World</data>
    <data>Bill Gate gays</data>
    <data>Steven King</data>

    My code can display Hello World only.

    How can I modify the code to display all? Please advise.
    ------------------------------------------
    Perl Kids Kiss Perl
    Stanley
    ------------------------------------------
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Location
    Colorado
    Posts
    46
    Rep Power
    14
    I think you just need to perform a loop inside your displayMeaning method. For example:

    Code:
    function displayMeaning(XMLObject) {
        var tmpNode = XMLObject.getElementsByTagName("data");
        for (int x=0; x <= tmpNode.length; x++) {
            var meaningTXT = tmpNode[x].text;
            meaning.value += meaningTXT;
        }
    }
    - MW
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    410
    Rep Power
    19
    Thanks for your advice.

    By the way, I heard that Flash can get XML from an CGI or something like that to change its content. Is it true?

    If it is true, I wanna ask if I want to change an image shown in a Flash frame by an image I uploaded somewhere. Is it possible?
    ------------------------------------------
    Perl Kids Kiss Perl
    Stanley
    ------------------------------------------

IMN logo majestic logo threadwatch logo seochat tools logo