Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confuse What should be my Xpath Expression?

My categories.xml file is given below

<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>

and My attibutes.xml file is given below

<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>

I bound my attributeDropdown on selection of categoriesDropDown. Code is given below

 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";

 }

Now the problem is two attributes named AC and Alarm are in two categories Real Estate and Property For Rent. How can I bind these attributes on selection of these categories ?

Insort what should be my Xpath Expression if attributes are in multiple categories?

like image 412
Chintan Avatar asked Nov 13 '22 10:11

Chintan


1 Answers

Maybe it isn't good solution, but you can use contains function, e.g.:

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

According to your code:

xd.XPath = string.Format("/attributes/attribute[contains(@categoryid, '{0}')]",
    categoriesDropDown.SelectedValue);
like image 193
Kirill Polishchuk Avatar answered Nov 16 '22 02:11

Kirill Polishchuk