1 / 16

A Generic SaveAs(XML)

A Generic SaveAs(XML). Paul Donohue. May 8th 2002 Hotel Senator Zürich. SaveAs(XML). The Desired Output. <?xml version='1.0'?> < table_name > < table_name _row> < col_name > Display Value </column_name> < col_name code=' Data ' > Display </col_name> </ table_name _row>

cliff
Download Presentation

A Generic SaveAs(XML)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Generic SaveAs(XML) Paul Donohue May 8th 2002 Hotel Senator Zürich

  2. SaveAs(XML) The Desired Output <?xml version='1.0'?> <table_name> <table_name_row> <col_name>Display Value</column_name> <col_name code='Data' >Display</col_name> </table_name_row> </table_name>

  3. SaveAs(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

  4. SaveAs(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

  5. SaveAs(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

  6. SaveAs(XML) The Root Element • The root element is the dw update table • For a read-only dw the word “datawindow” is used ls_describe = "DataWindow.Table.UpdateTable" ls_dw_table_name = adw_save_me.Describe(ls_describe) IF ls_dw_table_name = "?" THEN ls_dw_table_name = "Datawindow" END IF

  7. SaveAs(XML) The Loops • There are 2 loops • One for the rows and one for the columns ll_max_rows = adw_save_me.RowCount() ll_max_cols = Long(dw.Object.DataWindow.Column.Count)

  8. SaveAs(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) + ".ColType") dw.Describe("#" + String(col_idx) + ".Edit.Style")

  9. SaveAs(XML) Get The Data • Truncate the first 5 characters of the data type • Call the appropriate GetItem function

  10. SaveAs(XML) Format The Data • For dddw, ddlb & radio buttons use the display value • For edit masks apply the mask ls_describe = Evaluate('LookUpDisplay(" + ls_col_name + ")', " + String(ll_row) + ")" ls_display_value = dw.Describe(ls_describe) ls_describe = ls_col_name + ".EditMask.Mask" ls_edit_mask = adw_save_me.Describe(ls_describe)

  11. SaveAs(XML) Adding An Element • Column data is added as an element • dddw, ddlb & radio buttons also have an attribute • Any markup codes are replaced

  12. SaveAs(XML) Saving The XML File • FileWrite can write only 32766 bytes at a time • Use a loop to write chunks of data chunk = 32765 start = 1 stop = chunk DO WHILE FileWrite(file, Mid(xml, start, stop)) > 0 start += chunk stop += chunk LOOP

  13. SaveAs(XML) Other Information • Concatenating strings is slow • BLOBs will improve performance • ERROR : End element was missing the character '> ' Caused by FileWrite truncating data • ERROR : Invalid at the top level of the document Caused by writing a BLOB to the file

  14. Demonstration

  15. PowerBuilder 9 XML Support in PB9 • XML Services • PBDOM – DOM in PowerScript • SaveAs(XML) • ImportFile(XML!)

  16. Questions If you have any questions about this presentation or you would like a copy of the PowerBuilder objects please email me or visit my web site. Email : info@pauldonohue.com Web : www.pauldonohue.com

More Related