Topic Options
#44804 - 08/29/13 04:35 AM long XML line
Neil KMC Offline
OL Newbie

Registered: 06/14/13
Posts: 9
When using XmlGet, is there a way to break long lines of text so they move on to the next line (rather than running off the edge of the page)? smile

Top
#44805 - 08/29/13 09:58 AM Re: long XML line [Re: Neil KMC]
wags Offline
OL User

Registered: 06/07/11
Posts: 69
Loc: New York
What kind of object are you using? If you use a text object, then create a variable in that (right-click in the text box, "select data") it will automatically wrap according to the width constraint of the text object.

Top
#44806 - 08/29/13 10:57 AM Re: long XML line [Re: Neil KMC]
Neil KMC Offline
OL Newbie

Registered: 06/14/13
Posts: 9
I had to use presstalk due to the need to insert carriage returns. I've seen some code for using XmlGet but I'm not sure how to incorporate it.

define(&i, integer, 0)
define(&s, string, '')
define(&curstr, string, '')
margin(3.4,0)

&s :=stringreplace(XmlGet('/fields[1]/Week1-Monday[1]'),'\015\012','|')
for(&i, 1, 1, length(&s))
if(mid(&s, &i, 1) = '|')
showcenter(&curstr)
crlf(0.4)
&curstr := ''
elseif()
&curstr := &curstr + mid(&s, &i, 1)
endif()
endfor()

showcenter(&curstr)

Top
#44808 - 08/29/13 11:37 AM Re: long XML line [Re: Neil KMC]
wags Offline
OL User

Registered: 06/07/11
Posts: 69
Loc: New York
If your text is wrapped in a paragraph, it will still respect the width constraint. The only catch is that you can't use "crlf()" in a paragraph. Looking at your code, you could use "BeginParagraph" for each "line" of data you have, then when you encounter a pipe character, instead of doing the crlf(0.4), end the paragraph and begin a new one.

The paragraph gives you extra settings for margins, leading, etc.

I think that will be your best bet!

Top
#44814 - 08/29/13 12:27 PM Re: long XML line [Re: Neil KMC]
wags Offline
OL User

Registered: 06/07/11
Posts: 69
Loc: New York
I kicked this around a little more and I think you can greatly simplify your code too. Instead of manually stepping through each piece of your string looking for the pipe character, try using the search() function in PressTalk. Here's my stab at what your new code needs to look like. Note that you'll need to fill in a couple blanks (and remove the << >>!) and adjust the settings to your particular needs. I tried to match what you were going for in your original code sample.

Code:
define(&s, string, '')
&s := stringreplace(XmlGet('/fields[1]/Week1-Monday[1]'),'\015\012','|')

search(&s,'|')
  beginparagraph(3.4,<<width you want>>,0,'center',0.4)
    show(&s)
  endparagraph()
endsearch()

% if your data doesn't end with that | delimiter you
% will need to do one more 'show' or the last chunk
% of data will not display.
beginparagraph(3.4,<<width you want>>,0,'center',0.4)
  show(&s)
endparagraph()


Edited by wags (08/29/13 12:29 PM)

Top