aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML Parsing - how to read unknown number of values 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 "XML Parsing - how to read unknown number of values" Watch "XML Parsing - how to read unknown number of values" New topic
Author

XML Parsing - how to read unknown number of values

Marie O' Driscoll
Greenhorn

Joined: Mar 19, 2010
Posts: 11
Hi,

I am confused about how I should approach the following problem and do not know how I should go about recoding it:

I am currently trying to solve a bug in a simulator I use. Below is an excerpt of the code from the simulator:



So the above code reads a line from an xml file such as the following:

shape="1000.70,461.07 1009.76,464.12"/>

However there are cases in the xml where the “shape” attribute has more than 4 values e.g.

shape="1000.70,461.07 1003.27,462.12 1005.00,463.32 1005.87,464.68 1005.90,466.20"/>

I need to change the above code so it can read all the shape values (I do not know how many there will be as it can vary). I want to read them in such that the first set of values e.g. 1000.70,461.07 go into variables xfrom, yfrom, the last set of values e.g. 1005.90,466.20 go into variables xto, yto and all the ones in the middle go into variable x1,y1, x2,y2, x3,y3 etc.

Can someone please advise me how to go about this (even in pseudo code, I can look up the syntax myself if necessary).

Many thanks in advance.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18843
    
  40

Looks pretty straightforward. From your code, the vals array will get bigger as more points are provided, so you can easily check the size of the array for the number of points and act accordingly.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Marie O' Driscoll
Greenhorn

Joined: Mar 19, 2010
Posts: 11
Hi Henry,

Thanks for the reply.

How will I assign the second set of values to x1,y1, third set of values to x2,y2 etc. Must I use a for loop for this? And following on from that how will I know when I'm at the last set of values so that I can assign them to the xto, yto variables?

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML Parsing - how to read unknown number of values