Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DOM parsing  RSS feed

Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a scenario like below, If someone can help me out to do it best way it would be great.

I receive an invoice in to my java program with 1000 lines . But the backend I am talking to cannot handle all 1000. Hence I need to do follow,

Send first 200 lines (as a dom document) get a reply .
Then send 100 lines at a time and get the reply and send it to the client at the end.

When I get 1000 lines I put is in to a String instance variable in a method. Then I need to get first 200 lines then 100 at a time.

Question is this. Say actual invoice line lenth is 50bytes. Client might not send all the fields in the invoice line. some may be empty. When I populate in a DOM document I use all the fields as below,

String lines = "";
for (int x = 1; i.getLineCount() > x - 1; x++){
lines +=
_xmlutil.node("DistGLNumber" + x, _xmlutil.escapeXML(i.getLine(x - 1).getGl())) +
_xmlutil.node("DistRC" + x, _xmlutil.escapeXML(i.getLine(x - 1).getRc())) +
_xmlutil.node("DistCorp" + x, _xmlutil.escapeXML(i.getLine(x - 1).getCorp())) +
_xmlutil.node("DistAmount" + x, _xmlutil.escapeXML(i.getLine(x - 1).getLineAmount().toString())) +
_xmlutil.node("DistAmountSW" + x, _xmlutil.escapeXML(i.getLine(x - 1).getAMOUNT_SWITCH())) +
_xmlutil.node("DistAssetType" + x, _xmlutil.escapeXML(i.getLine(x - 1).getAssetType())) +
_xmlutil.node("DistAssetRC" + x, _xmlutil.escapeXML(i.getLine(x - 1).getAssetRC())) +
_xmlutil.node("DistProjectCode" + x, _xmlutil.escapeXML(i.getLine(x - 1).getProjectCode())) +
_xmlutil.node("DistProjectNumber" + x, _xmlutil.escapeXML(i.getLine(x - 1).getProjectNumber())) ;

Can I take the 200*50chars as my first chunk from the String "lines"
Next start with position 10001 and go up to 100*50 bytes in "lines" ?

I hope I gave sufficient info for you to answer.

Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's focus on what the String that holds all 1000 records looks like.

Are all records exactly the same length? You said 50 bytes, but then said some fields may be "empty". Do empty fields make the record shorter?

For all the same length, you can use RandomAccessFile and the position calculation you showed: seek( recordnumber * recordsize ) where record number is 0 to 999.

Is there a delimiter between records? Could you put a /n or something after each record? It sounds like you're making this String so maybe you can introduce field or record delimiters.

For delimited records you can use string.split() to make an array of Strings. Or maybe you could make some kind of Collection instead of a giant String in the first place.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!