Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    xml select options

    I'm trying to convert a string to xml and then fill a select box with that info. Not working Thoughts?

    var test = "<NewDataSet<Table><GenreID>d0e583d7-393d-47b1-8f47-e1b814e6d7c6</GenreID><Name>Politics</Name></Table><Table><GenreID>37f4a8ad-98d8-4b2c-9c30-4e2ff00dee2a</GenreID><Name>Shopping</Name></Table></NewDataSet>";

    var xmlobject = (new DOMParser()).parseFromString(test, "text/xml");
    // get a reference to the root-element "NewDataSet"
    var root = xmlobject.getElementsByTagName('NewDataSet')[0];
    // get reference to "table" element

    var Tables = root[0].getElementsByTagName("Table");
    // in the "table" we have a GenreID, so get that
    var genreID = Tables[0].getElementsByTagName("GenreID");
    var name = Tables[0].getElementsByTagName("Name");

    for (i=0;i<=genreID.length;i++)
    {
    document.forms['genreform'].genre.options[0] = new Option(name[i],genreID[i]);
    }

    Thanks,

    Ted

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by warmdownhere View Post
    I'm trying to convert a string to xml and then fill a select box with that info. Not working Thoughts?

    var test = "<NewDataSet<Table><GenreID>d0e583d7-393d-47b1-8f47-e1b814e6d7c6</GenreID><Name>Politics</Name></Table><Table><GenreID>37f4a8ad-98d8-4b2c-9c30-4e2ff00dee2a</GenreID><Name>Shopping</Name></Table></NewDataSet>";
    invalid xml
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    good catch, but I had cut out a bunch of the nodes so it didn't take up the page with xml. the xml is correct.

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by warmdownhere View Post
    var root = xmlobject.getElementsByTagName('NewDataSet')[0];
    // get reference to "table" element

    var Tables = root[0].getElementsByTagName("Table");
    if the xml is formed correctly then this must be the problem, you've taken the first element from the nodelist and assigned it to root...but you're still accessing root as if it were a nodelist
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #5
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have made some changes and Im getting closer, think. The options are now filling in, but are all [object].

    var test = "<NewDataSet><Table><GenreID>1cb45e3b-b2ed-4614-9343-bf21a9cfea20</GenreID><Name>Music</Name></Table><Table><GenreID>d0e583d7-393d-47b1-8f47-e1b814e6d7c6</GenreID><Name>Politics</Name></Table><Table><GenreID>37f4a8ad-98d8-4b2c-9c30-4e2ff00dee2a</GenreID><Name>Shopping</Name></Table></NewDataSet>";
    var genrename;
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(test);

    genrename = xmlDoc.getElementsByTagName("Name");
    for (var i=0; i<genrename.length; i++)
    {
    document.forms['genreform'].genre.options[i] = new Option(genrename ,genrename);
    }


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •