File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dom Parser picking up only first tag

 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • 0
  • Mark post as helpful
  • send pies
  • 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

 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic