Steve,


Interesting question, and not a bad idea for a new tag. Here’s some code to 
help you on your way.



First I did it using straight forward string manipulation on the html. The 
first few lines simulate the URL response. You’ll have to match up the FINDSTRs 
to your actual data (attributes, extra spaces, line breaks, etc). I documented 
each line.



<@! construct example array>

<@ASSIGN array <@ARRAY VALUE="1A,1B,1C;2A,2B,2C;3A,3B,3C">>



<@! set array as text string to simulate URL response>

<@ASSIGN tarray <@VAR array TYPE=text>>



<@! strip table and /table tags>

<@ASSIGN tarray <@REPLACE STR=@@tarray FINDSTR='<table border=<@DQ>1<@DQ>>'>>

<@ASSIGN tarray <@REPLACE STR=@@tarray FINDSTR='</table>'>>



<@! strip tr td tag combo>

<@ASSIGN tarray <@REPLACE STR=@@tarray FINDSTR='<tr><td>'>>



<@! strip /td only from /td /tr tag combo>

<@ASSIGN tarray <@REPLACE STR=@@tarray FINDSTR='</td></tr>' REPLACESTR='</tr>'>>



<@! build array using remaining table tags as delimiters>

<@ASSIGN newarray <@ARRAY CDELIM="</td><td>" RDELIM="</tr>" VALUE=@@tarray>>



<@! done>

@@newarray



Second, I used the fact that HTML is XML and parsed it with DOM and then read 
out the content by accessing the /table/tr/td nodes. Again you may need to 
tweak the code to match your situation if it’s not as straight forward as my 
example, but you shouldn’t need to worry about attributes and white space with 
this method.



<@! construct example array>

<@ASSIGN array <@ARRAY VALUE="1A,1B,1C;2A,2B,2C;3A,3B,3C">>



<@! set array as text string to simulate URL response>

<@ASSIGN tarray <@VAR array TYPE=text>>



<@! create a DOM out of the table html>

<@ASSIGN dom <@DOM @@tarray>>



<@! read the td elements from the DOM, per each tr, into a new array>

<@FOR STOP=<@NUMROWS ARRAY=<@ELEMENTVALUE dom XPATH=/table/tr type=array>>>

<@ADDROWS newarray <@TRANSPOSE <@ELEMENTVALUE dom 
XPATH=/table/tr[position()=<@CURROW>]/td TYPE=array>>>

</@FOR>



<@! done>

@@newarray



One final note, this code will likely error if the table is empty and will 
definitely error if the table is corrupted/malformed, or if there is any usage 
of colspan or rowspan. You’ll likely want to put some sanity checks on the URL 
response before you process it with one of the above methods.



Good luck!



Robert





From: Fogelson, Steve [mailto:[email protected]]
Sent: Sunday, December 11, 2011 12:30 AM
To: [email protected]
Subject: Witango-Talk: HTML to TeraScript Array



I am using the <@url> tag to retrieve inventory from another server. It is 
returned in html <table>, </table>, <tr>, </tr>, <td> and </td>. No other 
output options at this time.



I need to convert it to a TeraScript array.



Looking for the quickest efficient way to do this.



Thanks



Steve Fogelson



  _____

To unsubscribe from this list, please send an email to [email protected] 
with "unsubscribe witango-talk" in the body.



----------------------------------------

To unsubscribe from this list, please send an email to [email protected] 
with "unsubscribe witango-talk" in the body.

Reply via email to