Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot read childnodes in XML - NEED HELP!

 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an xml file and want to read certain tags and attributes..
This is my file


Basically, what i cant figure out is how to read the attribute <Concepto> and others from inside<Conceptos>


In my codeI am able to get <Conceptos> but just not able to read its childs... This is my code.



PLEASE ANY POINTERS WOULD BE GREATLY APPRECIATE IT.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeepItDown
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would use the org.w3c.dom methods for Element -

use getElementsByTagName( "Conceptos" )

with one of those Elements getElementsByTagName("Concepto")

with a Concepto Element getAttribute("whatever")

Harold's Processing XML with Java book is available free online, just search. It is loaded with practical examples.

Bill
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William,
Thanks for the reply... can I get a link, please!
 
Claudiu Chelemen
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, have you tried getting them directly?

Also, from what I can see, your second concepto has some quotes in the descripcion attribute, that should be escaped.

Claudiu
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, as Paul told you here, don't use == to compare strings. Use the String.equals method.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claudiu, William;
You have been of great help actually with constructive comments, than you very much! I was able to solve my problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic