2012-02-04 27 views
5

tập tin categories.xml của tôi là đưa ra dưới đâyConfuse Biểu thức Xpath của tôi nên là gì?

<categories> 
    <root name="Cars -Vehicles" id="CV"></root> 
    <root name="Personals" id="PER"></root> 
    <root name="Real Estate" id="RE"></root> 
    <root name="Property For Rent" id="PFR"></root> 
    <root name="Community" id="COM"></root> 
</categories> 

và tập tin attibutes.xml của tôi là đưa ra dưới đây

<attributes> 

    <attribute value="ethnicity=ethnicity_african_american" name ="American Indian" categoryid="PER"/> 
    <attribute value="ethnicity=ethnicity_asian_pacific_islander" name ="Asian - Pacific Islander" categoryid="PER"/> 
    <attribute value="ethnicity=ethnicity_caucasian" name ="Caucasian" categoryid="PER"/> 


    <attribute value="amenities=amenities_ac" name ="AC" categoryid="RE, PFR"/> 
    <attribute value="amenities=amenities_alarm" name ="Alarm" categoryid="RE, PFR"/> 

</attributes> 

tôi bị ràng buộc attributeDropdown tôi về lựa chọn nhà categoriesDropDown. Mã được đưa ra dưới đây

protected void ddCategories_SelectedIndexChanged(object sender, EventArgs e) 
{ 
      XmlDataSource xd = new XmlDataSource(); 
      xd.DataFile = Server.MapPath("Xmls") + "\\attributes.xml"; 
      xd.XPath = "/attributes/attribute[@categoryid='" + 
         categoriesDropDown.SelectedValue.ToString() + "']"; 

      attributeDropdown.DataSource = xd; 
      attributeDropdown.DataTextField = "name"; 
      attributeDropdown.DataValueField = "value"; 

      attributeDropdown.DataBind(); 

     // categoriesDropDown.DataTextField = "name"; 
     // categoriesDropDown.DataValueField = "id"; 

} 

Bây giờ vấn đề là hai thuộc tính tên ACAlarm là trong hai loại Bất động sảntài sản Cho thuê. Làm cách nào tôi có thể ràng buộc các thuộc tính này trong việc chọn các danh mục này?

Tách biệt biểu thức Xpath của tôi nếu thuộc tính ở nhiều danh mục là gì?

Trả lời

1

Có lẽ nó không phải là giải pháp tốt, nhưng bạn có thể sử dụng contains chức năng, ví dụ .:

/attributes/attribute[contains(@categoryid, 'category')] 

Theo mã của bạn:

xd.XPath = string.Format("/attributes/attribute[contains(@categoryid, '{0}')]", 
    categoriesDropDown.SelectedValue); 
Các vấn đề liên quan