treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Parsing XML with JavaScript: No value is returned

  • Hey Guys!
    I'm working on a project where I need to load data via AJAX-Request. To do this I use a XML-File. Everything just works fine until I try to get the values of an "activity".

    THE XML-FILE

    <item>
      <id>19</id>
      <date>2013-01-23</date>
      <department>Some text...</department>
      <text>Some text...</text>
      <status>1</status>
      <user_id>1</user_id>
    
      <activities>
        <count>1</count>
    
        <activity>
          <a_id>20</a_id>
          <a_item_id>19</a_item_id>
          <a_user_id>1</a_user_id>
          <a_time>3.0</a_time>
          <a_text>Some text...</a_text>
        </activity>
      </activities>
    </item>
    

    My approach was the following:

    var a_id = xmlDoc.getElementsByTagName("activity")[0].childNodes[0].nodeValue;
    

    But this returns nothing.

    Any idea how to "navigate" to "a_id"?

  • Could you make a CodePen? That might make it a bit easier to see what's going on and try stuff out.