w3pop.com :: ÍøÂçѧԺ :: APPML :: °¸ÀýÑо¿£º¿Í»§
This chapter demonstrates AppML on the Customers table in the Northwind database.
ÕâÕ½²ÊöÁËAppML»ùÓÚNorthwindÊý¾Ý¿âÖпͻ§±í¸ñµÄÓ¦Óá£
The "Customers" AppML description: northwind/customers.xml
“¿Í»§”AppMLÃèÊö£ºnorthwind/shippers.xml
HTML Report: appml.asp?appname=northwind/customers&displaytype=report
HTML ±¨¸æ£ºappml.asp?appname=northwind/customers&displaytype=report
The link above runs the AppML HTML report service. To be able to run an AppML HTML report, the AppML description must contain an <htmlreport> tag.
ÉÏÊöÁ´½ÓÔËÐÐÁËAppML HTML ±¨¸æ·þÎñ¡£ÎªÁËÄܹ»ÔËÐÐAppML HTML ±¨¸æ£¬AppMLÃèÊö±ØÐë°üº¬Ò»¸ö<htmlreport>±êÇ©¡£
We see that the report contains a header ("Customers"), a table listing the different companies along with their contact person, address, city, and country. The report also lists the number of records at the bottom. The title and sql selection shown in the report, is taken from the <title> tag (under the <appml> tag) and the <sql> tag inside <htmlreport>. The number of records are automatically added by AppML.
ÎÒÃǶ¼¿´µ½£¬Õâ·Ý±¨¸æ°üº¬ÁËÒ»¸öҳü£¨“¿Í»§”£©£¬Ò»¸ö¸ù¾ÝÁªÏµÈË¡¢µØÖ·¡¢³ÇÊк͹ú¼ÒÁоٲ»Í¬²úÆ·µÄ±í¸ñ¡£±¨¸æ»¹Ôڵײ¿ÁоÙÁ˼ǼµÄÊýÁ¿¡£±¨¸æÖÐչʾµÄ ±êÌâ ºÍSQLÑ¡¼¯ÊÇ´Ó<htmlreport>ÄÚ²¿µÄ<title>±êÇ©£¨ÔÚ<appml>֮ϣ©ºÍ< sql>±êÇ©ÌáÈ¡³öÀ´µÄ¡£¼Ç¼ÊýÁ¿Í¨¹ýAppML×Ô¶¯±»Ìí¼ÓµÄ¡£
This report also have a Filter button. If you click on the Filter button, you can filter and sort the report. You can also determine in what format you want to show the report (Normal, Word, Excel, or XML).
Õâ·Ý±¨¸æ»¹°üº¬ÁËÒ»¸ö¹ýÂ˰´Å¥¡£Èç¹ûÄãµã»÷Á˹ýÂ˰´Å¥£¬Äã¾Í¿ÉÒÔ±¨¸æ½øÐйýÂ˺ͷÖÀà¡£ÄãͬÑù¿ÉÒÔ¶¨Ò屨¸æÏÔʾµÄ¸ñʽ£¨Õý³£¡¢Word¡¢Excel »ò XML£©¡£
The <filters> tag in "customers.xml" looks like this:
“customers.xml” ÖеÄ<filters>±êÇ©ÏÔʾÈçÏ£º
<filters> |
We see that the <filters> tag contains an <orderby> tag, several <query> tags, and an <orderselect> tag.
ÎÒÃÇ¿´µ½£¬<filters>±êÇ©°üº¬ÁËÒ»¸ö<orderby>±êÇ©¡¢²¿·Ö<query>±êÇ©ºÍÒ»¸ö<orderselect>±êÇ©¡£
The <orderby> tag specifies which field the report should be ordered by. In this case, the report will be ordered by the Companyname field in the Customers table.
<orderby>±êǩָ¶¨Á˱¨¸æ¸ÃÒÔʲô×Ö¶ÎΪ»ù×¼½øÐÐÅÅÐò¡£ÔÚÕâ¸ö°¸ÀýÖУ¬¸Ã±¨¸æ½«Í¨¹ý¿Í»§±í¸ñÖеĹú¼ÒÃû³Æ×ֶνøÐÐÅÅÐò¡£
The <query> tags defines which fields the user can search on. The <field> tag defines the name of the field in the table, and the <label> tag defines the label that will be visible for the user. In this case, the user can search on "Companyname", "City", and "Country".
<query>±êÇ©¶¨ÒåÁËÓû§¿ÉÒÔ¸ù¾Ýʲô×ֶνøÐÐËÑË÷¡£<field>±êÇ©¶¨ÒåÁ˱í¸ñÖеÄ×Ö¶ÎÃû³Æ£¬< label>±êÇ©¶¨ÒåÁ˱êÇ©¶ÔÓÚÓû§À´ËµÊÇ·ñ¿ÉÊÓ¡£ÔÚÕâ¸ö°¸ÀýÖУ¬Óû§¿ÉÒÔ¸ù¾Ý “¹«Ë¾Ãû³Æ” ¡¢“³ÇÊД ÒÔ¼° “¹ú¼Ò” ½øÐÐËÑË÷¡£
Inside the "City" and "Country" <query> tag, there is an <sql> tag. The <sql> tag indicates that AppML should create a drop-down box where the user can select an existing city and/or country to search on.
ÔÚ“³ÇÊД ºÍ“¹ú¼Ò” ÖеÄ<query>±êÇ©ÊÇ×÷Ϊ<sql>±êÇ©³öÏֵġ£<sql>±êÇ©°µÊ¾ÁËAppMLÓ¦¸Ã´´½¨Ò»¸öÏÂÀ¿òÒÔ·½±ãÓû§Ñ¡ÔñÏÖÓеÄ×Ö¶ÎÈ瓳ÇÊД »ò “¹ú¼Ò” À´½øÐÐËÑË÷¡£
The <orderselect> tag specifies other order-by options for the user. Here, the user can determine if the report should be ordered by "Companyname", "Contactname", "City", or "Country".
<orderselect>±êǩΪÓû§Ö¸¶¨ÁËÆäËüÀàÐ͵ÄÅÅÐòÑ¡Ïî¡£ÕâÀÓû§¿ÉÒÔ¶¨ÒåËüÓ¦¸Ã°´ÕÕ“¹«Ë¾Ãû³Æ”¡¢“ÁªÏµÃû³Æ”¡¢³ÇÊД »òÊÇ“¹ú¼Ò”À´½øÐÐÅÅÐò¡£
The <filters> tag is used by both <htmlreport> and <htmllist>.
<filters>±êÇ©¿ÉÓÃÓÚ<htmlreport>±êÇ©ºÍ<htmllist>±êÇ©¡£
HTML Form: appml.asp?appname=northwind/customers&displaytype=form
HTML ±íµ¥£ºappml.asp?appname=northwind/customers&displaytype=form
The link above runs the AppML form service. To be able to run AppML form, the AppML description must contain an <htmlform> tag. The AppML description must also contain a <maintable> tag and a <keyfield> tag (inside the <database> tag).
ÉÏÊöÁ´½ÓÔËÐÐÁËAppML±íµ¥·þÎñ¡£ÎªÁËÄܹ»ÔËÐÐAppML HTML ±¨¸æ£¬AppMLÃèÊö±ØÐë°üº¬Ò»¸ö<htmlform>±êÇ©¡£AppMLÃèÊö±ØÐ뻹Ҫ°üº¬Ò»¸ö<maintable>±êÇ©ºÍ Ò»¸ö<keyfield>±êÇ©£¨Î»ÓÚ<database>±êÇ©ÄÚ²¿£©¡£
The link above takes you to a page with a blank form. Here you can add a new record. AppML automatically adds New, Submit, and Delete buttons.
ÉÏÊöÁ´½Ó¿ÉÒÔʹÄãÖØÐ´ò¿ªÒ»¸öȫеĿհ×Ò³Ãæ¡£Äã¿ÉÒÔÔÚÀïÃæÌí¼ÓȫеļǼ¡£AppML»á×Ô¶¯Ìí¼ÓмǼ°´Å¥¡¢Ìá½»°´Å¥ºÍɾ³ý°´Å¥¡£
This time we have specified the look of the form with standard HTML code. The <htmlform> tag in "customers.xml" looks like this:
ÎÒÃÇÒѾÒÀ¾ÝHTML´úÂëµÄ±ê×¼Ö¸¶¨ÁË±íµ¥µÄÍâ¹Û¡£“customers.xml”ÖеÄ<htmlform>±êÇ©ÈçÏ£º
<htmlform> <elements> <form> |
The sql selection for the form is specified in the <sql> tag inside <htmlform>.
¹ØÓÚ±íµ¥µÄsqlÑ¡¼¯±»Ö¸¶¨ÔÚÁË<htmlform>ÖÐ<sql>±êÇ©µÄÄÚ²¿¡£
The <elements> tag is a container for the data fields in an HTML form or in an editable HTML list that should fulfill special criterions. In the code above, we specify that the field customerid is required (cannot be left blank in the form). If a user leave this field blank, AppML will generate an error message telling that the field has to be filled with data.
<element>±êÇ©ÊÇHTML±íµ¥»ò¿É±à¼µÄHTMLÁÐ±í£¨ÕâЩÁÐ±í±ØÐë×ñÑÒ»¶¨µÄ¹æ·¶£©ÖеÄÊý¾Ý×Ö¶ÎÈÝÆ÷¡£ÔÚÉÏÊö´úÂëÖУ¬ÎÒÃÇÖ¸³ö“¹« ˾Ãû³Æ” ×ֶκ͓ÁªÏµÃû³Æ” ×Ö¶ÎÊDZØÒªµÄ£¨²»¿ÉÒÔÔÚ±íµ¥ÖÐÒÔ¿Õ°×ÏÔʾ£©¡£Èç¹ûÒ»¸öÓû§¶ÔÕâÁ½¸ö×Ö¶ÎÁôÒÔ¿Õ°×£¬AppML½«²úÉú´íÎóÐÅÏ¢£¬²¢ÌáʾÄãÌîÂú±í¸ñ¡£
The look of the input form is specified inside the <form> and </form> tags. Here we use standard HTML (like <table> tags, <fieldset> and <legend>, and <input>).
ÊäÈë±íµ¥µÄÍâ¹Û±»Ö¸¶¨ÔÚÁË<form>±êÇ©ºÍ</form>±êÇ©µÄÄÚ²¿¡£ÔÚÕâÀÎÒÃÇʹÓõÄÊDZê×¼µÄHTML´úÂ루È磺< table>±êÇ©¡¢<fieldset>±êÇ©¡¢<legend>±êÇ©ºÍ<input>±êÇ©£©¡£
Notice that to show the data from a database and to make the data updateable, we set the id attribute of the input tags equal to the fieldnames in our sql selection.
×¢Ò⣺¶ÔÓÚÏÔʾÊý¾Ý¿âÊý¾ÝºÍ¸üÐÂÊý¾ÝÀ´Ëµ£¬ÉèÖÃ<input>±êÇ©ÖеÄidÊôÐÔºÍÉèÖÃsql Ñ¡ÏÖеÄ×Ö¶ÎÃûÊôÐÔµÄЧ¹ûÊÇÒ»ÑùµÄ¡£
HTML List: appml.asp?appname=northwind/customers&displaytype=list
HTML ÁÐ±í£º appml.asp?appname=northwind/customers&displaytype=list
The link above runs the AppML list service. To be able to run AppML list, the AppML description must contain an <htmllist> tag.
ÉÏÊöÁ´½ÓÔËÐÐÁËAppMLÁбí·þÎñ¡£ÎªÁËÄܹ»´´½¨AppMLÁÐ±í£¬AppMLÃèÊö±ØÐë°üº¬Ò»¸ö<htmllist>±êÇ©¡£
We see that the list contains a header ("Customers"), the number of records in the list, a Filter button, a New button, a Report button, and a table listing the different customers.
ÎÒÃǶ¼¿´µ½£¬Õâ·Ý±¨¸æ°üº¬ÁËÒ»¸öҳü£¨“¿Í»§”£©¡¢ÁбíÖеļǼÊý¡¢Ò»¸ö¹ýÂ˰´Å¥¡¢Ò»¸öа´Å¥¡¢Ò»¸ö±¨¸æ°´Å¥ºÍÒ»¸öÂÞÁв»Í¬²úÆ·µÄ±í¸ñ°´Å¥ÒÔ¼°ÂÞÁÐÁ˲»Í¬¿Í»§µÄ±í¸ñ¡£
The title and sql selection shown in the report, is taken from the <title> tag and the <sql> tag inside <htmllist>. The number of records and the buttons are automatically added by AppML.
±¨¸æÖÐչʾµÄ±êÌâºÍSQLÑ¡¼¯ÊÇ´Ó<htmllist>ÄÚ²¿µÄ<title>±êÇ©ºÍ<sql>±êÇ©ÌáÈ¡³öÀ´µÄ¡£¼Ç¼µÄÊýÁ¿ºÍ°´Å¥ÊÇ×Ô¶¯Ìí¼Óµ½AppMLÖеġ£
The Filter button is automatically added because the AppML description contains a <filters> tag.
¹ýÂ˰´Å¥ÊÇ×Ô¶¯Ìí¼ÓµÄ£¬ÒòΪAppMLÃèÊö°üº¬ÁËÒ»¸ö<filters>±êÇ©¡£
The New button is automatically added because the AppML description contains an <htmlform> tag.
Р°´Å¥ÊÇ×Ô¶¯Ìí¼ÓµÄ£¬ÒòΪAppMLÃèÊö°üº¬ÁËÒ»¸ö<htmlreport>±êÇ©¡£
The Report button is automatically added because the AppML description contains an <htmlreport> tag.
±¨¸æ°´Å¥ÊÇ×Ô¶¯Ìí¼ÓµÄ£¬ÒòΪAppMLÃèÊö°üº¬ÁËÒ»¸ö<htmlreport>±êÇ©¡£
The Folder image to the left of each records is automatically added because the AppML description contains an <htmlform> tag. If you click on the Folder image, you will be taken to the AppML form.
ÿÌõ¼Ç¼×ó±ßµÄÎļþ¼ÐͼÏñÊÇ×Ô¶¯Ìí¼ÓµÄ£¬ÒòΪAppMLÃèÊö°üº¬ÁËÒ»¸ö<htmlform>±êÇ©¡£Èç¹ûÄãµã»÷ÁËÎļþ¼ÐͼÏñ£¬Ä㽫»á½øÈëAppML±íµ¥¡£
The <htmllist> tag in "customers.xml" looks like this:
“customers.xml” ÎļþµÄ<htmllist>±êÇ©ÈçÏ£º
<htmllist> |
In the list, notice the column called "Orders". This column is a link that goes to the "Orders" application and shows the orders for each customer.
ÔÚÁбíÖÐÎÒÃÇ¿ÉÒÔ·¢ÏÖÃûΪ“Orders”µÄÁС£Õâ¸öÁÐÁ´½Óµ½“Orders” Ó¦ÓóÌÐòÖУ¬²¢ÇÒ£¬Ëü½«ÏÔʾÿ¸ö¿Í»§µÄ˳Ðò¡£
XML Report:
appml.asp?appname=northwind/customers&displaytype=report&type=xml
XML ±¨¸æ£º
appml.asp?appname=northwind/customers&displaytype=report&type=xml
The link above runs the AppML XML service.
ÉÏÊöÁ´½ÓÔËÐÐÁËAppML XML ·þÎñ¡£
The AppML XML report service above will generate an XML report based on the sql defined in the <htmlreport> element. The XML report's root element is <table>. The first element after <table> is <sql>, which lists the sql used in the description. Then there will be one <row> element for each record in the sql. The <row> element contains one element for each field in the sql.
ÉÏÊöµÄAppML XML±¨¸æ·þÎñ½«»á²úÉúÒ»¸ö»ùÓÚÔÚ<htmlreport>ÔªËØÖж¨ÒåµÄsqlÀ´²úÉúÒ»¸öXML±¨¸æ¡£XML±¨¸æµÄ¸ùÔªËØÊÇ< table>¡£ÔÚ<table>Ö®ºóµÄµÚÒ»¸öÔªËØÊÇ<sql>£¬ËüÂÞÁÐÁËÔÚÃèÊöÖÐʹÓõÄsql¡£¶ÔÓÚsqlÖÐÿһÌõ¼Ç¼¶ø ÑÔ£¬¶¼»á°üº¬Ò»¸ö<row>ÔªËØ¡£<row>ÔªËØÎªsqlÖеÄÿÌõ×ֶΰüº¬ÁËÒ»¸öÔªËØ¡£
To run all the AppML services above in one, use the following link:
appml.asp?appname=northwind/customers
Ï£ÍûÔËÐÐÉÏÃæµÄAppML·þÎñ£¬¿ÉÒÔµã»÷ÏÂÃæµÄÁ´½Ó£º
appml.asp?appname=northwind/customers
ÆÀÂÛ (0)
All