xml:
<?xml version="1.0" ?>
<Form >
<textbox>
<property name='hello' value='world' posx='10px' posy='111px'/>
</textbox>
<button>
<property id='button1' text='click'/>
</button>
</Form>
</xml>
如何读取它,使之呈现在page上呢?
方法:
1:读取该xml文件,用
switch(ControlType)
{
case 'textbox':
....
break;
case ....
}
这样的方法太麻烦了,
有没有更好的办法呢?
请大家帮忙,
<?xml version="1.0" ?>
<Form >
<textbox>
<property name='hello' value='world' posx='10px' posy='111px'/>
</textbox>
<button>
<property id='button1' text='click'/>
</button>
</Form>
</xml>
如何读取它,使之呈现在page上呢?
方法:
1:读取该xml文件,用
switch(ControlType)
{
case 'textbox':
....
break;
case ....
}
这样的方法太麻烦了,
有没有更好的办法呢?
请大家帮忙,
那数据库的数据如何导入到界面的控件呢?
又是如何将控件中的数据修改后,保存到库呢?
目前我只想到了一种switch case的方法,
但这种方法不是很灵活,
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;namespace Webserv2.Enjoy.Web.Controls.Server
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Navigator: System.Web.UI.Control
{
string transformFilePath;
string sourceFilePath;
public string TransformFile
{
get
{
return transformFilePath;
}
set
{
transformFilePath = value;
}
} public string SourceFile
{
get
{
return sourceFilePath;
}
set
{
sourceFilePath = value;
}
} protected override void OnInit( EventArgs e )
{
base.OnInit( e );
} protected override void Render( HtmlTextWriter writer )
{
XPathDocument xdoc = new XPathDocument( Context.Server.MapPath( sourceFilePath ) );
XslTransform xslt = new XslTransform();
xslt.Load( Context.Server.MapPath( transformFilePath ) );
xslt.Transform( xdoc, null, writer );
}
}
}
NavMenu.xml <?xml version="1.0" ?>
<NavMenu title="Enjoy Online">
<Category title="影视剧场" icon="/Enjoy/images/DVDlogo.gif">
<MenuItem title="国内影片" link="#" />
<MenuItem title="国外大片" link="#" />
</Category>
<Category title="网络文学" icon="/Enjoy/images/Booklogo.gif">
<MenuItem title="古典文学" link="#" />
<MenuItem title="现代文学" link="#" />
</Category>
</NavMenu>NavMenu.xslt
<?xml version="1.0"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:template match="/NavMenu">
<table width="150" border="0" cellspacing="0" cellpadding="0" class="Navigator_Table">
<tr>
<td colspan="2" class="Navigator_Header_Cell">
<xsl:value-of select="@title"/>
</td>
</tr>
<xsl:for-each select="Category">
<!-- CATEGORY START -->
<tr >
<td width="40" align="center">
<img align="absmiddle">
<xsl:attribute name="src">
<xsl:value-of select="@icon"/>
</xsl:attribute>
</img>
</td>
<td width="110" class="Navigator_Category_Cell">
<xsl:value-of select="@title"/>
</td>
</tr>
<xsl:for-each select="MenuItem">
<!-- MENU ITEM START -->
<tr>
<td width="40">
<br/>
</td>
<td width="110" class="Navigator_Item_Cell">
<a class="Navigator_Item_Link">
<xsl:attribute name="href">
<xsl:value-of select="@link"/>
</xsl:attribute>
<xsl:value-of select="@title"/>
</a>
</td>
</tr>
<!-- MENU ITEM END -->
</xsl:for-each>
<!-- CATEGORY END -->
</xsl:for-each>
</table>
</xsl:template></xsl:stylesheet>
但是 xlst 格式化这种技术,好像是将已定义好的页面数据以"某种风格"展现出来,有点像css,但是比css要高级.
但是,这种技术,应该不适合我的需求。我的xml文件定义了界面的控件布局信息,只是要通过xml解析将它show到页面上。另外,控件(如:TextBox)的数据还是存放在库里的。
主要是该xml文件是由Form Designer是由生成的源文件,它保存了控件的属性。
另外,个人还想到了一种方法是:
将该xml文件直接解析成:html,然后插在Form当中。
当然,在解释的过程中,要访问数据库对控件进行数据初始化。另外,
还请大家多多帮忙,说出一些更灵活的解决方案,
合适的再出100分。
--如果保存在xml的form节点下的格式是按aspx里相同格式的话,
那不是html源代码吗?如果是这样,那又是不可行的,因为我的数据要从数据库取得,
所以无论如何,都是要解析一下xml文件的。另外,请问:什么叫"ParseContol"这个方法呢?
可以交流一下吗?
目前我的两个思路是:
1:用面向对像的方法,动态加载控件,
2:将xml文件解析成html代码,然后加在<form>.</form>当中。
想与banni2003(木木) 交流一下,一同成长,ok?
<asp:textbox runat="server"></textbox>
这种形式的话就可以直接用ParseControl这个方法解释生成控件。具体可以按F1键看帮助要解释xml的话,就是只能逐个解释了。你说麻烦也没办法。