Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parsing question

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
I have a document in this form, and I'm trying to create new objects based on this info.<br><br>(note: this is not Java code, but rather a text file. I'll explain it all after.)<br><br>Class1 {<br>&nbsp;&nbsp;id: 123<br>&nbsp;&nbsp;serialNumber:&nbsp;&nbsp;456<br>&nbsp;&nbsp;name: myClass1Object<br>&nbsp;&nbsp;followers: Class2 {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id: 456<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serialNumber: 789<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: myClass2Object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;followers: Class3 {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id: 456<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serialNumber: 789<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: myClass2Object<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;followers: Class2 {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id: 321<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serialNumber: 654<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: myClass2Object2<br>&nbsp;&nbsp;}<br>}<br><br>This text file is an interpretation of a object heirarchy. I have 3 different classes. For the purposes of the question, they are all seemingly identical. They have 4 different fields; the &quot;followers&quot; field returns a Vector. In this example, the Class1 object has a &quot;followers&quot; vector with two Class2 objects in it; the first Class2 object has one Class3 object in it.<br><br>I need to write a parser; probably recursive. This parser will read the series of brackets and instantiate new objects of whatever type they are (for example, the first line should make the program instantiate a new object of type Class1).<br><br>I can make use of either StreamTokenizer or StringTokenizer (or anything else that fits my needs, but I can't think of anything). I might end up using both.<br><br>I'm feeling hard pressed for where to start- I have a general idea, but my mind is getting fuzzy on implementation. Anybody have any ideas? Hopefully I'll have this settled before any replies come in... but just in case. :eek:) <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."
 
Liam,<br><br>I hope you have a perfectly 'great' reason for not using XML and existing parsing code and/or mechanisms.<br><br>Note: &quot;I like to re-invent wheels&quot; does not qualify as a 'great' reason.<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete
 
Yeah, I'd love to use Perl, I really would. But I need to instantiate Java objects with this info, so I'm using Java. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Liam,<br><br>That doesn't really answer my question since free Java source is available for parsing XML.<br><br>-pete
 
well maybe I'll look into it... where could I find an overview? <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
thanks, but I changed the format of my text document and StreamTokenizer now throws everything into hashtables in just a few lines of code. For now, I'll go with what I know, and sometime later I'll take a look at that. Thanks. I actually remember that article from looking over my subscription... I'll remember to go back to that one. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top