1

I'm uploading xml file and accessing values in a php class. Everything is going smooth but when i try to access $middle_of_month value I have a debug error called

"Call to undefined method DOMNodeList::getElementsByTagName()"

Here's how xml looks like

...
<Fdr>
  <MiddleOfMonth>
      <Data Value="0" MonthNumber="1" />
      ...

I get the other tags correct I verified with debug.

$fdr             = $key->getElementsByTagName(tag_constants::TAG_FDR);
$middle_of_month = $fdr->getElementsByTagName(tag_constants::TAG_MIDDLE_OF_MONTH);

I have the error in $middle_of_month line. I debugged like 2 hours and still couldn't figure out what's wrong. Any help would be appreciated

Edit :

tag_constants::TAG_FDR -> Fdr
tag_constants::TAG_MIDDLE_OF_MONTH ->MiddleOfMonth

Edit 2 :

$middle_of_month = $fdr->item(0)->getElementsByTagName(tag_constants::TAG_MIDDLE_OF_MONTH); 

seems to solve the problem

3
  • should TAG_MIDDLE_OF_MONTH ->MiddleOfMont be TAG_MIDDLE_OF_MONTH ->MiddleOfMonth? May be you just mistyped? Commented Sep 18, 2013 at 6:41
  • Sorry, i mistyped here, in code it's correct. I editted here Commented Sep 18, 2013 at 6:45
  • And I added a control to see if $fdr is null or not and it's not null Commented Sep 18, 2013 at 6:49

1 Answer 1

2

getElementsByTagName() returns a NodeList, and as the error implies, NodeLists do not in turn have this method (only Elements and Documents do).

You will need to pick an item from $fdr to run getElementsByTagName() on; perhaps like:

$fdr->item(0)->getElementsByTagName(tag_constants::TAG_MIDDLE_OF_MONTH);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.