admin管理员组

文章数量:1391947

I'm trying to extract an element called lastupdated from a parent node called episode: data -> Episode -> lastupdate

if I wrote:

episodeList = xmlDoc.getElementsByTagName("Episode");
console.log(episodeList[1].getElementsByTagName("lastupdated")[0])

it returns me the item zero of a list of length 1 but with the lastupdated tags

If I wrote:

console.log(episodeList[1].getElementsByTagName("lastupdated")[0].nodeValue)

it returns null! why is that?

responding: textValue returns null

xml part: TextContent also return null. here goes the xml:

<Data>
<Series>
<id>75760</id>
<Actors>
|Josh Radnor|Cobie Smulders|Neil Patrick Harris|Jason Segel|Alyson Hannigan|Bob Saget|
</Actors>
<Airs_DayOfWeek>Monday</Airs_DayOfWeek>
<Airs_Time>8:00 PM</Airs_Time>
<ContentRating>TV-PG</ContentRating>
<FirstAired>2005-09-19</FirstAired>
<Genre>|Comedy|</Genre>
<IMDB_ID>tt0460649</IMDB_ID>
<Language>en</Language>
<Network>CBS</Network>
<NetworkID/>
<Overview>
How I Met Your Mother is a edy about Ted and how he fell in love. It all started when Ted's best friend, Marshall, dropped the bombshell that he was going to propose to his longtime girlfriend, Lily, a kindergarten teacher. At that moment, Ted realized that he had better get a move on if he, too, hopes to find true love. Helping him in his quest is his friend Barney, a confirmed bachelor with endless, sometimes outrageous opinions, a penchant for suits and a foolproof way to meet women. When Ted meets Robin, he's sure it's love at first sight, but destiny has something else in store.
</Overview>
<Rating>9.2</Rating>
<RatingCount>381</RatingCount>
<Runtime>30</Runtime>
<SeriesID>33700</SeriesID>
<SeriesName>How I Met Your Mother</SeriesName>
<Status>Continuing</Status>
<added/>
<addedBy/>
<banner>graphical/75760-g25.jpg</banner>
<fanart>fanart/original/75760-45.jpg</fanart>
<lastupdated>1333146863</lastupdated>
<poster>posters/75760-12.jpg</poster>
<zap2it_id>EP00753796</zap2it_id>
</Series>
<Episode>
<id>1159571</id>
<Combined_episodenumber>1</Combined_episodenumber>
<Combined_season>0</Combined_season>
<DVD_chapter/>
<DVD_discid/>
<DVD_episodenumber/>
<DVD_season/>
<Director/>
<EpImgFlag>1</EpImgFlag>
<EpisodeName>Robin Sparkles Music Video - Let's Go to the Mall</EpisodeName>
<EpisodeNumber>1</EpisodeNumber>
<FirstAired>2006-11-20</FirstAired>
<GuestStars/>
<IMDB_ID/>
<Language>en</Language>
<Overview/>
<ProductionCode/>
<Rating>4.0</Rating>
<RatingCount>1</RatingCount>
<SeasonNumber>0</SeasonNumber>
<Writer/>
<absolute_number/>
<airsafter_season/>
<airsbefore_episode>10</airsbefore_episode>
<airsbefore_season>2</airsbefore_season>
<filename>episodes/75760/1159571.jpg</filename>
<lastupdated>1275339740</lastupdated>
<seasonid>23219</seasonid>
<seriesid>75760</seriesid>
</Episode>

I'm trying to extract an element called lastupdated from a parent node called episode: data -> Episode -> lastupdate

if I wrote:

episodeList = xmlDoc.getElementsByTagName("Episode");
console.log(episodeList[1].getElementsByTagName("lastupdated")[0])

it returns me the item zero of a list of length 1 but with the lastupdated tags

If I wrote:

console.log(episodeList[1].getElementsByTagName("lastupdated")[0].nodeValue)

it returns null! why is that?

responding: textValue returns null

xml part: TextContent also return null. here goes the xml:

<Data>
<Series>
<id>75760</id>
<Actors>
|Josh Radnor|Cobie Smulders|Neil Patrick Harris|Jason Segel|Alyson Hannigan|Bob Saget|
</Actors>
<Airs_DayOfWeek>Monday</Airs_DayOfWeek>
<Airs_Time>8:00 PM</Airs_Time>
<ContentRating>TV-PG</ContentRating>
<FirstAired>2005-09-19</FirstAired>
<Genre>|Comedy|</Genre>
<IMDB_ID>tt0460649</IMDB_ID>
<Language>en</Language>
<Network>CBS</Network>
<NetworkID/>
<Overview>
How I Met Your Mother is a edy about Ted and how he fell in love. It all started when Ted's best friend, Marshall, dropped the bombshell that he was going to propose to his longtime girlfriend, Lily, a kindergarten teacher. At that moment, Ted realized that he had better get a move on if he, too, hopes to find true love. Helping him in his quest is his friend Barney, a confirmed bachelor with endless, sometimes outrageous opinions, a penchant for suits and a foolproof way to meet women. When Ted meets Robin, he's sure it's love at first sight, but destiny has something else in store.
</Overview>
<Rating>9.2</Rating>
<RatingCount>381</RatingCount>
<Runtime>30</Runtime>
<SeriesID>33700</SeriesID>
<SeriesName>How I Met Your Mother</SeriesName>
<Status>Continuing</Status>
<added/>
<addedBy/>
<banner>graphical/75760-g25.jpg</banner>
<fanart>fanart/original/75760-45.jpg</fanart>
<lastupdated>1333146863</lastupdated>
<poster>posters/75760-12.jpg</poster>
<zap2it_id>EP00753796</zap2it_id>
</Series>
<Episode>
<id>1159571</id>
<Combined_episodenumber>1</Combined_episodenumber>
<Combined_season>0</Combined_season>
<DVD_chapter/>
<DVD_discid/>
<DVD_episodenumber/>
<DVD_season/>
<Director/>
<EpImgFlag>1</EpImgFlag>
<EpisodeName>Robin Sparkles Music Video - Let's Go to the Mall</EpisodeName>
<EpisodeNumber>1</EpisodeNumber>
<FirstAired>2006-11-20</FirstAired>
<GuestStars/>
<IMDB_ID/>
<Language>en</Language>
<Overview/>
<ProductionCode/>
<Rating>4.0</Rating>
<RatingCount>1</RatingCount>
<SeasonNumber>0</SeasonNumber>
<Writer/>
<absolute_number/>
<airsafter_season/>
<airsbefore_episode>10</airsbefore_episode>
<airsbefore_season>2</airsbefore_season>
<filename>episodes/75760/1159571.jpg</filename>
<lastupdated>1275339740</lastupdated>
<seasonid>23219</seasonid>
<seriesid>75760</seriesid>
</Episode>
Share Improve this question edited Mar 31, 2012 at 19:22 Marco Martins asked Mar 31, 2012 at 18:48 Marco MartinsMarco Martins 4691 gold badge6 silver badges15 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

You need to use nodeValue instead of nodevalue. Javascript is case sensitive and there is no nodevalue property of DOM Node.

UPDATE: Also you need to use textContent if you want text value within xml node. For more information look textContent and nodeValue references.

本文标签: javascript xml nodevalue not workingStack Overflow