GeeCON Prague 2014*
The moose likes XML and Related Technologies and the fly likes Dom Parser picking up only first tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Dom Parser picking up only first tag" Watch "Dom Parser picking up only first tag" New topic
Author

Dom Parser picking up only first tag

Lou Pelagalli
Ranch Hand

Joined: Nov 11, 2003
Posts: 150
    
    1
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

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42043
    
  64
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).


Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
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

Joined: Nov 11, 2003
Posts: 150
    
    1
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
Marshal

Joined: Mar 22, 2005
Posts: 42043
    
  64
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.
 
GeeCON Prague 2014
 
subject: Dom Parser picking up only first tag