我的頁面上有一個XmlDataSource和一個GridView。在Page_Load事件中,我應用XPath根據用戶的輸入過濾xml元素,LexiqueXmlDataSource.XPath = 'Some_XPath_here';
並且它工作正常。循環通過XmlDataSource中的XML元素後面的代碼
我想要的是訪問XmlDataSource在應用XPath表達式(從而得到它們的編號)後從代碼隱藏中返回的元素。
我試過GetXmlDocument()
方法,但它返回的是整個原始的Xml文件,而不是使用XPath過濾的元素。
編輯:
這裏是一些代碼和情景我想:
protected void Page_Load(object sender, EventArgs e)
{
string xpath = "/lexique/item[starts-with(@acronym, '" + filter + "')]";
LexiqueXmlDataSource.XPath = xpath;
// Here the XmlDataSource have filtered the xml elements to return to the GridView
//I want to know how many element passed this filter using the XmlDataSource itself
}
謝謝。
不`計數(your_expression_here)`工作? – Flack 2011-02-12 22:36:39
我想從XmlDataSource訪問元素,而不是自己訪問xml文件 – 0xFF 2011-02-12 22:49:44
我認爲還不清楚......您是否想訪問「Page_Load」事件中的選定節點,但是不需要再次查詢XML源?那麼你不需要XPath表達式。重新標記 – 2011-02-12 23:19:44