/    Sign up×
Community /Pin to ProfileBookmark

getElementsByTagName("pspagetitle")[x] is undefined

The following code is giving me the error “xmldoc.getElementsByTagName(“pspagetitle”)[x] is undefined”. Having said that I can not for the life of me figure it out. I have been staring at this for two hours and I decided to put my ego aside and ask for some help. I know that this something simple I just can’t put my finger on it. So if there are any gurus out there that can help me it would be appreciated.

Note: The initial request for the document is working fine, if I place an alert [I]alert(typeof root);[/I] it returns object and [I]alert(root)[/I]; returns [object HTMLCollection]. I have also included a copy of my XML document (via inline comment) that is being loaded via XMLHttpRequest()

[CODE]
//var xmldoc = http_request.responseXML;
root = xmldoc.getElementsByTagName(“portalsettings”);

alert(typeof root); // <– returns object
alert(root); // <– returns [object HTMLCollection]

for(x = 0; x <= root.length; x++)
{
/*
<portal>
<productinfo>
<!– Product Info Should be Set In This Element –>
<prodline>My Product Line Name</prodline>
<prodserial>V35-OOUN74DH7</prodserial>
<prodmodel>135</prodmodel>
<prodmanfdate>00.00.0000</prodmanfdate>
</productinfo>
<portalsettings>
<!– Portal Information –>
<pspagetitle>Login Portal</pspagetitle>
<pscustomername>Customer Name</pscustomername>
<!– Video Recorder Settings –>
<psheadend>
<headendurl>http://www.video.someniftyurlthatishidden.com</headendurl>
</psheadend>
</portalsettings>
<portal>
*/

// The following line is the one causing my eventual brain aneurysm.
var m_pageTitle = xmldoc.getElementsByTagName(“pspagetitle”)[x].childNodes[0].nodeValue;
var m_customerName = xmldoc.getElementsByTagName(“pscustomername”)[x].childNodes[0].nodeValue;

//Not entirely sure this next line is right.. I have not been able to get past the original problem.
var m_psHeadEndUrl = xmldoc.getElementsByTagName(“psheadend”)[x].childNodes[0].childNodes[0].nodeValue;

$(‘#highlight-black’).append(‘<strong>’ + m_pageTitle + ‘</strong>’);
document.title = m_pageTitle;
alert(m_psHeadEndUrl);
}
[/CODE]

Thank you,
John

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineMay 14.2010 — [CODE]for(x = 0; x <[B][COLOR="Red"]=[/COLOR][/B] root.length; x++)[/CODE][/QUOTE]You're reading past the end of the array.[CODE]for(var x = 0; x < root.length; x++)[/CODE]
×

Success!

Help @S1ghup spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...