A Generic Save AsXML Paul Donohue May 8
- Slides: 16
A Generic Save. As(XML) Paul Donohue May 8 th 2002 Hotel Senator Zürich
Save. As(XML) The Desired Output <? xml version='1. 0'? > <table_name_row> <col_name>Display Value</column_name> <col_name code='Data' >Display</col_name> </table_name_row> </table_name>
Save. As(XML) Design Guidelines • The function must be generic • The function must cater for large datasets • The function must handle special markup codes • The function must cater for edit styles
Save. As(XML) Function Overview • Add the XML declaration • Add the root element • Loop through each row in the datawindow • Loop through each column in the row • Get the column data • Format the data • Add the data as an element • Save the data to a text file
Save. As(XML) The XML Declaration • The first line of any XML file • This is hard coded • The XML is being built up as a string ls_add_to_xml_doc = "<? xml version='1. 0'? >" ls_xml_doc = ls_add_to_xml_doc
Save. As(XML) The Root Element • The root element is the dw update table • For a read-only dw the word “datawindow” is used ls_describe = "Data. Window. Table. Update. Table" ls_dw_table_name = adw_save_me. Describe(ls_describe) IF ls_dw_table_name = "? " THEN ls_dw_table_name = "Datawindow" END IF
Save. As(XML) The Loops • There are 2 loops • One for the rows and one for the columns ll_max_rows = adw_save_me. Row. Count() ll_max_cols = Long(dw. Object. Data. Window. Column. Count)
Save. As(XML) Get The Column Details • Find the column’s name, data type & edit style dw. Describe("#" + String(col_idx) + ". Name") dw. Describe("#" + String(col_idx) + ". Col. Type") dw. Describe("#" + String(col_idx) + ". Edit. Style")
Save. As(XML) Get The Data • Truncate the first 5 characters of the data type • Call the appropriate Get. Item function Data Type Function CHAR( Get. Item. String DATE Get. Item. Date TIME Get. Item. Time DATET Get. Item. Date. Time DECIM Get. Item. Decimal INT, LONG, REAL, ULONG, NUMBE Get. Item. Number
Save. As(XML) Format The Data • For dddw, ddlb & radio buttons use the display value • For edit masks apply the mask ls_describe = Evaluate('Look. Up. Display(" + ls_col_name + ")', " + String(ll_row) + ")" ls_display_value = dw. Describe(ls_describe) ls_describe = ls_col_name + ". Edit. Mask" ls_edit_mask = adw_save_me. Describe(ls_describe)
Save. As(XML) Adding An Element • Column data is added as an element • dddw, ddlb & radio buttons also have an attribute • Any markup codes are replaced Markup Code Ampersand (&) Less than (<) Greater than (>) Apostrophe (‘) Quote (“) Replacement & < > ' "
Save. As(XML) Saving The XML File • File. Write can write only 32766 bytes at a time • Use a loop to write chunks of data chunk = 32765 start = 1 stop = chunk DO WHILE File. Write(file, Mid(xml, start, stop)) > 0 start += chunk stop += chunk LOOP
Save. As(XML) Other Information • Concatenating strings is slow • BLOBs will improve performance • ERROR : End element was missing the character '> ' Caused by File. Write truncating data • ERROR : Invalid at the top level of the document Caused by writing a BLOB to the file
Demonstration
Power. Builder 9 XML Support in PB 9 • XML Services • PBDOM – DOM in Power. Script • Save. As(XML) • Import. File(XML!)
Questions If you have any questions about this presentation or you would like a copy of the Power. Builder objects please email me or visit my web site. Email : info@pauldonohue. com Web : www. pauldonohue. com
- Si te printojme nje dokument
- Difference between save and save as
- Caller save vs callee save
- Anam cara frases
- The life you save could be your own
- The life you save may be your own meaning
- Irony in good country people
- Hci design patterns
- Worldedit save schematic
- The human footprint worksheet
- Triase
- Flickr
- So save your breath and the money you spent
- Mighty to save
- Short text about pollution
- Save us lord while we are awake
- Lijevi pritoci save