• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Parsing - how to read unknown number of values

 
Marie O' Driscoll
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marie O' Driscoll
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic