Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DOM PArser: Reading value of node etc

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know the meaning of various methods which DOM parser provides.

1) NodeList nodes=element.getChildNodes();
what is stored in nodes above?

2)Node node=nodes.item(i);// where i iterates over nodes.getLength();

what does item method do?

3)NodeList nlList=element.getElementsByTagName("Title").item(0).getChildNodes();

Why is "0" hardcoded in item?. What if i write "1" instead of "0"

4)Node nValue=(Node)nList.item(0)

What does above do??


Below is the xml file




Please explain
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you don't need to ask that question here. There is API documentation which tells you what the meaning of every single method in every single class is. Just go and read it.

I don't even need to provide a link, because the links are already automatically there in your post. Look at your original post and you'll see that the class names are actually links. Follow them.

Of course if you have questions about what you read there, don't hesitate to ask. But asking us to explain something for which the official explanation is readily available, that's just a waste of your time and ours.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. But i dont think there would be anyone who would be here in this forum without knowing how to find what a method does. Ofcourse, i can google the method name and find it out what it does. But what i wanted to knw was how element, node and node list differs.

Basic idea of providing the xml in my first post was to know how does node, element and node list differs. May be i was not categorical enough

Element i understand, for eg say <Title> tag in above eg.

Now say i do call a getDocumentElement() on the document object, hope i guess reference to the rootElement i.e <Library.>

Now, say with this root element, i do a getChildNodes(), then i guess i should get 2 nodes, i.e Book as there are two occurences of <book>

Now , i do
Node node=nodes.item(0), then i would get reference to the first "Book" Node. Now i want to read the element values like Title,
Author, etc , for which i would call getElementsByTagName with "tags" as parameters...


I dont know whether my understandinng is correct...Please verify.. Thanks for patience
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that sort of looks like an accurate description of what code like that might do if you ran it. But the question "What will happen when I run this code" is also one which there is no point in asking on a forum. It's much more straightforward to just run the code and see what happens.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic