xpath in asp.net c# web appication selection multiple values in xmldocument.selectnodes
I have an xml document like this... this xml doc provides content for webpages
<pages id="pages">
<page id="Shipping-Services">
<linktext>Shipping Services</linktext>
<pagelink>Shipping-Services</pagelink>
<content>Shipping Services</content>
<H1>Shipping Services开发者_如何学C</H1>
<LogoALT>Shipping Services</LogoALT>
<Title>Shipping Services</Title>
<Desc>Shipping Services</Desc>
<KeyWords>My, Key, Words</KeyWords>
<banner></banner>
<market>value</market>
</page>
</pages>
I am trying to search based on page id and market using xmldocument.selectnodes
XmlDocument xdoc2 = new XmlDocument();
xdoc2.Load(Server.MapPath("~/xml/Pagesextend.xml"));
XmlNodeList xList2 = xdoc2.SelectNodes(".//*[@id='" + Request.QueryString[1].ToString() + "']");
tried this.... not working
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("~/xml/Pages.xml"));
XmlNodeList xList = xdoc.SelectNodes(".//*[@id='" + Request.QueryString["p"].ToString() + "' and contains(market, '" + Request.QueryString["m"].ToString() + "']");
I can search by ID no problem, but adding the second market parameter is stumping me... Any assistance would be great.
what xpath would I enter to use two parameters how I have the xml setup?
You missed the closing ')' on the contains.
XmlDocument xdoc = new XmlDocument();
xdoc.Load(Server.MapPath("~/xml/Pages.xml"));
XmlNodeList xList = xdoc.SelectNodes(".//*[@id='" + Request.QueryString["p"].ToString() + "' and contains(market, '" + Request.QueryString["m"].ToString() + "')]");
I usually prefer to use string.Format() for XPath:
XmlNodeList xList = xmlDoc.SelectNodes(string.Format(".//*[@id='{0}' and contains(market, '{1}')]", Request.QueryString["p"].ToString(), Request.QueryString["m"].ToString()));
Helps a bit when you need to look for minor syntax errors like missing parenthesis.
精彩评论