This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Dom Parser picking up only first tag

 
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My Dom parser is picking up only the first tag, in this case <gram>. Can someone tell me why <carat> is not included?

Code and console output below.

Thanks,

Lou

XML file MKSFactors2.xml



DomParser.java


Console Output
Starting MeasurementList
DomParser.parseXmlFile()
dom=[#document: null]
parseDocument()
getMeasurement(Element element)
Measurement Added
Number of Measurements = 1.
Measurement label=Weight, type=Metric, name=Gram, toMKS=1.0, fromMKS=1.0

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was going to try running it, but the Measurement class is missing. Please post an SSCCE (<-- that's a link), or post the missing class(es).
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

textVal = el.getFirstChild().getNodeValue();



I always suspect that getFirstChild() returns some formatting crlf or spaces, and not the Node you are expecting.

Bill
 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf,

Sorry I didn't post all the classes.

All files follow my signature.

MeasurementList is the main class.

MKSFactors2.xml is a small file for testing and development. I have a much larger file for production after I get the smaller one working.

Thanks,

Lou

MeasurementList.java


Measurement.java


DomParser.java


MKSFactors2.xml
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After a quick look at the code, I don't see how it could be adding more measurements to the list than a single one. In the parseDocument method it adds one measurement for each "weights" tag - of which there is only one. I think you need to iterate through all the children of the weights node, and add them as appropriate.
 
We're all out of roofs. But we still have tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic