• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Cannot read childnodes in XML - NEED HELP!  RSS feed

 
Ranch Hand
Posts: 107
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeepItDown
 
Author and all-around good cowpoke
Posts: 13078
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: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William,
Thanks for the reply... can I get a link, please!
 
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: 107
  • 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
Boost this thread!