0

My code is like this

   var tariffdate = PriceSheet.children('TariffEffDate')[1].text;

Where I expect to get data inside TariffEffDate tag. But it gives me undefined instead.

I can Get <TariffEffDate>1999-01-01T00:00:00</TariffEffDate> as a result for code

  console.log(PriceSheet.children('TariffEffDate')[1])

But when I add .text to get data inside this node it is giving me undefined. Can anyone point out what I am doing wrong here?

4
  • You need to use .nodeValue instead of .text IIRC. Commented May 15, 2015 at 12:00
  • @h2ooooooo I have tried and result is Null Commented May 15, 2015 at 12:05
  • Someone else had to use [1].firstChild.nodeValue instead of [1].nodeValue. Perhaps that would fix it? Commented May 15, 2015 at 12:06
  • @h2ooooooo That solved the issue, You can add it as an answer Commented May 15, 2015 at 12:18

1 Answer 1

1

You need to use Node.nodeValue instead of .text.

.children('TariffEffDate')[1] will give you a HTMLElement that inherits Node, but it won't give you a leaf node, meaning that this HTMLElement might have multiple children. This is why you cannot get the value of (technically) multiple child-nodes. You can access the first node by calling Node.firstChild.

Essentially, you want your final code to be:

var tariffdate = PriceSheet.children('TariffEffDate')[1].firstChild.nodeValue;
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.