Why not use BeanShell? I'm actually parsing a site and storing data in a list.
I have a common.cml I use to define common variables (note you must use 2.1
trunk version of WH):
<?xml version="1.0" encoding="UTF-8"?><!-- Common variables and functions --><configxmlns="[url]http://web-harvest.sourceforge.net/schema/2.1/core[/url]"charset="UTF-8"><script><![CDATA[ // HTTP client defaults http.client.params.soTimeout = 5000; http.client.params.connectionManagerTimeout = 5000; http.client.httpConnectionManager.params.connectionTimeout = 5000; // Default user agent String userAgent = "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"; // List of Maps to be returned to Java application List mapList = new ArrayList(); ]]></script></config>
Then for example create a couple functions to parse XHTML and add to a List of
Maps
<!-- Return list of Strings parsing each element of xmlDoc. --><functionname="getList"><return><loopitem="item"index="i"><list><!-- Get a list of TR elements of name DataContainer using URL postUrl --><xpathexpression='//tr[@name="DataContainer"]'><value-ofexpr="${xmlDoc}"/></xpath></list><body><xpathexpression="//span[@name='INCIDENT']/text()"><value-ofexpr="${item}"/></xpath><xpathexpression="(//span[@name='DATE_TIME']/text(), ' ')[1]"><value-ofexpr="${item}"/></xpath><xpathexpression="(//span[@name='eTIME']/text(), ' ')[1]"><value-ofexpr="${item}"/></xpath><xpathexpression="(//span[@name='DESCRIPTION']/text(), ' ')[1]"><value-ofexpr="${item}"/></xpath><xpathexpression="(//span[@name='STREET']/text(), ' ')[1]"><value-ofexpr="${item}"/></xpath><xpathexpression="(//span[@name='SUBDIVISION']/text(), ' ')[1]"><value-ofexpr="${item}"/></xpath></body></loop></return></function><!-- Process calls List and store fields in Map, then add to List. --><functionname="addToMapList"><script><![CDATA[ // Date format simpleDateFormat = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm"); List list = calls.toList(); Iterator listIterator = list.iterator(); Map map = null; String tempStr = null; while (listIterator.hasNext()){ map = new HashMap(); // ID for MCSO map.put("entity_id", 1); // Event number map.put("event_num", listIterator.next().toString()); // Timestamp as java.util.Date which must be converted to java.sql.Timestamp for database map.put("event_time", simpleDateFormat.parse(listIterator.next().toString()+" "+listIterator.next().toString())); // Description tempStr = listIterator.next().toString(); if (tempStr.toString().trim().equals("")) { map.put("description", null); } else { map.put("description", tempStr); } // Main location tempStr = listIterator.next().toString(); if (tempStr.toString().trim().equals("")) { map.put("location_main", null); } else { map.put("location_main", tempStr); } // Alternate location 1 tempStr = listIterator.next().toString(); if (tempStr.toString().trim().equals("")) { map.put("location_alt1", null); } else { map.put("location_alt1", tempStr); } // These don't exist, so set to null map.put("case_num", null); map.put("location_alt2", null); map.put("location_alt3", null); mapList.add(map); } ]]></script></function>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I want to read file line by line and add each line in list.
Hello
Have the same requirement myself, no luck yet, report back if you find the
ways and means,
Regards
Jason
Why not use BeanShell? I'm actually parsing a site and storing data in a list.
I have a common.cml I use to define common variables (note you must use 2.1
trunk version of WH):
Then for example create a couple functions to parse XHTML and add to a List of
Maps