aspose file tools*
The moose likes Java in General and the fly likes Cannot read childnodes in XML - NEED HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cannot read childnodes in XML - NEED HELP!" Watch "Cannot read childnodes in XML - NEED HELP!" New topic
Author

Cannot read childnodes in XML - NEED HELP!

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
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: 3169
    
  10
KeepItDown


Joanne
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
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: 99
William,
Thanks for the reply... can I get a link, please!
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 71

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: 3169
    
  10
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: 99
Claudiu, William;
You have been of great help actually with constructive comments, than you very much! I was able to solve my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot read childnodes in XML - NEED HELP!
 
Similar Threads
compiling error. Please help
Reading xml attributes in java
CMR problem in weblogic
Place Association
CMR problem in weblogic