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 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2009
    Location
    US
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Getting text in xml element

    Ok, Simpler question. I'm trying to get the text in an xml element. Instead of getting just the text in the first child element I'm getting the text of all the children elements. How can I get it from just the first?

    Code:
         var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
         
         function xmlload(filexml) 
           { 
             xmlDoc.async="false"; 
             xmlDoc.load(filexml); 
             xmlObj=xmlDoc.documentElement; 
          }
          
          xmlload('urlhere');
          
          document.getElementById("nmbr").value=myVar;
          myVar = xmlObj.childNodes(0).childNodes(19).firstChild.text;
    
          document.getElementById("comment_t").innerText= myVar;

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,324 Times in 4,290 Posts
    You *do* know this code will never work in any browser except MSIE, yes?

    Anyway, what's the XML look like???

    And in this line:
    Code:
     document.getElementById("nmbr").value=myVar;
    you haven't initialized myVar yet, so you should be getting nothing for that .value.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2009
    Location
    US
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Page I read forgot to mention that one apearently.. I do have the variable initialized, along with a few others. Just didn't think I need to indude all the initializations. In the wrong forum my next wuestion then.. need some way to read the xml that will work in the frame/browser that this is going to show in in Windows Presentation Foundation.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,324 Times in 4,290 Posts
    Two places in your code that depended on MSIE:

    new ActiveXObject ==>> ActiveX is strictly a MicroSlop technology.

    document.getElementById("comment_t").innerText ==>> innerText not available in other browsers.

    Not hard to make it work in all browsers.

    Don't see why this has anything (directly) to do with WPF. You do have to load the XML from a URL that is in the same domain as the page, of course. I assume you knew that?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Dec 2009
    Location
    US
    Posts
    39
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Yea I did. I've figured it out now. Sorry for taking so much of your time to no avail. :/

  • #6
    New Coder
    Join Date
    Aug 2010
    Location
    FL
    Posts
    35
    Thanks
    0
    Thanked 1 Time in 1 Post
    You should check out YQL (Yahoo Query Language) if you feel like researching alternative methods.


  •  

    Posting Permissions

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