Using xml config in ASP.NET application

2019-08-09 02:18发布

问题:

Is it a good programming way to use xml config file for building dynamic web interface with databinding, events etc ..?

<Sub Name="Matrix Report" Url="frmGridReportPanel.aspx">    
    <Report  Name="Repor Name" src="ConnectionStr" Url="frmGridReportPanel.aspx">
              <DataSource>
                <Server Type="Table">View_REPORT1</Server>
                <Client>null</Client>
              </DataSource>
              <FIELDS>
                <FIELD type="DropDownList" id="Table_ID" name="Table_Field_name" required="true">
                  <LOOKUP>MyTable</LOOKUP>
                  <DIMENSION>Table_ID</DIMENSION>
                  <DATATYPE>Int</DATATYPE>
                  <LENGTH>12</LENGTH>
                  <OPERATOR>=</OPERATOR>
                </FIELD>
                .....
              </FIELDS>
            </Report>
    ....
    <Sub/>

This is my xml. How i can configure the event triger for the controls.

Is there any open source that use xml congig file for build dynamicly the web page?

Any ideas?

回答1:

On some platforms, XML configuration files are the norm (for example, .NET).

Using XML can help if you make your element and attribute names meaningful, however will require a parser and/or deserializer in order to get into memory.

If this is too much overhead, you can use other methods (simple key-value pairs in a file, like most unix configuration files).

As such, there is no specific "best practice" - best practice it to follow the standard used in the platform/language you use.

I am not clear what that has to do with databinding, events and building a dynamic web site, however.


As for your specific requirement - a dynamic reporting toolbar, I would say a config file could be a good fit. It depends on the amount of data and whether it should be synchronized to another data store.

If most of the values for the filters need to by dynamic since they should correspond to values from a database, I would not use a config, but get the data from the database.