| Author |
Cannot read childnodes in XML - NEED HELP!
|
Eduardo Ponce de Leon
Ranch Hand
Joined: May 13, 2009
Posts: 97
|
|
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
Joined: Aug 05, 2005
Posts: 3011
|
|
|
KeepItDown
|
Joanne
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
Eduardo Ponce de Leon
Ranch Hand
Joined: May 13, 2009
Posts: 97
|
|
William,
Thanks for the reply... can I get a link, please!
|
 |
Claudiu Chelemen
Ranch Hand
Joined: Mar 25, 2011
Posts: 65
|
|
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
Joined: Aug 05, 2005
Posts: 3011
|
|
|
Also, as Paul told you here, don't use == to compare strings. Use the String.equals method.
|
 |
Eduardo Ponce de Leon
Ranch Hand
Joined: May 13, 2009
Posts: 97
|
|
Claudiu, William;
You have been of great help actually with constructive comments, than you very much! I was able to solve my problem.
|
 |
 |
|
|
subject: Cannot read childnodes in XML - NEED HELP!
|
|
|