#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    5
    Rep Power
    0

    javascript loading xml data for parameter


    hi,

    i'm a beginner i'm trying to access variable stored in an xml file from a javascript function embedded in a svg file. I ll repeat, i'm trying to access variable stored in an xml file from a javascript function embedded in a svg file.

    and i don't wanna use an activeX controler.

    I think it's possible to start like this, but it's the first time i manipulate XML so i'm a little bit inexperienced (forgive me before reading )

    the xml source call sourceParam.xml :

    <?xml version="1.0"?>
    <varSource>
    <mode> create</mode>
    <todo>draw</todo>
    <form>territory</form>
    <envDraw>mondial</envDraw>
    <drawingFrom>taiga</drawingFrom>
    </varSource>

    then in a initialize function of the javascript file :

    getURL ("sourceParam.xml",getParam);


    and the getParam function :

    function getParam( data )
    {
    if (data.success)
    {
    var doc_frag = parseXML ( data.content, svgdoc);
    childs=doc_frag.getChildNodes();

    var mode=childs.childNodes(1).firstChild.text;
    var todo=childs.childNodes(2).firstChild.text;
    var form=childs.childNodes(3).firstChild.text;
    var envDraw=childs.childNodes(4).firstChild.text;
    var drawingForm=childs.childNodes(5).firstChild.text;
    }
    else {alert ("Error reading file");}
    }

    My objective is to instanciate the variables according to the xml file, please help me to find this solution.

    thanks,

    wozoi
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Puerto Rico
    Posts
    208
    Rep Power
    13
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    5
    Rep Power
    0
    thanks but i said i don't wanna use an activeX controle and your answer begin with :

    new activeXObject ("Microsoft.XMLDOM");

    that's not what i'am looking for,

    thanks,

    wozoi
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    Puerto Rico
    Posts
    208
    Rep Power
    13
    oh sory dude, so you mean that the code you have can work in any browser and OS?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    JavaScript doesn't have any file i/o capabilities, let alone xml support. If you don't want to use Microsoft's xml object, then you're out of luck. This is maybe something that is best done server side?
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    5
    Rep Power
    0
    with this function getParam

    function getParam( data )
    {
    if (data.success)
    {
    var doc_frag = parseXML ( data.content, svgdoc); childs=doc_frag.childNodes.item(0).childNodes;
    var mode=childs.item(1).firstChild.data;
    var todo=childs.item(3).firstChild.data;
    var form=childs.item(5).firstChild.data;
    var envDraw=childs.item(7).firstChild.data;
    var drawingForm=childs.item(9).firstChild.data;
    alert(mode+"-"+todo+"-"+form+"-"+envDraw+"-"+drawingForm)

    }
    else {alert ("Error reading file");}
    }

    my parameter are well display in the alert box but javascript don't use them for initializing the component.

    what could i do to solve this problem?

    wozoi
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Well, I have no idea what parseXML is doing, but apparently it works. What do you mean by 'javascript don't use them for initializing the component?' What component? What are you trying to do with the data?
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    5
    Rep Power
    0
    I succeed to load my parameter with the use of a timeout of 250 that let enought time to charge the xml data.

    setTimeout("initialize2()",1000)}

    function initialize2()

    alert...

    thanks for your help. So it's possible without the use of an activeXcontroler
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Well, good, I guess.

    I'm still at a loss for what your problem was. If you need a timeout in your script, it's probably because your parseXML is parsing (or reading?) the string (file?) asynchronously, meaning it doesn't wait until it's done to return. If you want to change the behavior (like continuing your script once the file has loaded) the original link provided by CyberKill3r is a good one. It explains how to do xml with ActiveX for Explorer, and using the DOM for Netscape.

    I'd be real shocked if your parseXML function didn't use ActiveX though. If it doesn't, it would leave Explorer out in the cold, since the browser does not implement that part of the DOM, and like I said, JavaScript has no support for doing what you want.
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    5
    Rep Power
    0
    I just wanna find an other way.

    in fact my application don't use neither acitveX or the xml reading solution but function with Session variable but i wanted test some other way to "speak" with my javascript component.

    thanks for your help

IMN logo majestic logo threadwatch logo seochat tools logo