getting next xml node value
-
hi, i have next and previous buttons, when i click next i must get the next xml node value and if i click previous button it should display the previous node value. can anybody help in this regard. Thanks in advance.
-
hi, i have next and previous buttons, when i click next i must get the next xml node value and if i click previous button it should display the previous node value. can anybody help in this regard. Thanks in advance.
If you have a XmlNode-instance you can use PreviousSibling and NextSibling. Have a look here: http://msdn.microsoft.com/de-de/library/system.xml.xmlnode.nextsibling.aspx[^] Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
If you have a XmlNode-instance you can use PreviousSibling and NextSibling. Have a look here: http://msdn.microsoft.com/de-de/library/system.xml.xmlnode.nextsibling.aspx[^] Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
hi, thanks for the help. Actually i have a webpage which contains previous and next buttons. in the same page i have a frame where i have to change the value of the iframe src depending on the previous and next buttons. the value will be taken from XML node values. Please check the xml doc below. <?xml version="1.0" encoding="utf-8" ?> <portfolio> <portfolios id="0808"> <src link="http://www.yahoo.com"></src> </portfolios> <portfolios id="0809"> <src link="http://www.gmail.com"></src> </portfolios> <portfolios id="0810"> <src link="http://www.codeproject.com></src> </portfolios> <portfolios id="0811"> <src link="http://www.xyz.com"></src> </portfolios> </portfolio> and check my backend coding. protected void imgbtnNext_Click(object sender, ImageClickEventArgs e) { //string crnturl = Request.Url.ToString(); XmlDocument doc=new XmlDocument(); XmlNode root = doc.LastChild; if (root) { imgbtnNext.Enabled = false; } else { string myurl = Request.QueryString.Get("id").ToString(); XmlDataSource xsd = new XmlDataSource(); xsd.DataFile = "~/App_Data/portfolio.xml"; xsd.XPath = "portfolio/portfolios[@id='" + myurl + "']/src"; GridView ds = new GridView(); ds.DataSource = xsd; ds.DataBind(); iframeprojects.Attributes.Add("src", ds.Rows[0].Cells[0].Text.ToString()); } }
-
hi, thanks for the help. Actually i have a webpage which contains previous and next buttons. in the same page i have a frame where i have to change the value of the iframe src depending on the previous and next buttons. the value will be taken from XML node values. Please check the xml doc below. <?xml version="1.0" encoding="utf-8" ?> <portfolio> <portfolios id="0808"> <src link="http://www.yahoo.com"></src> </portfolios> <portfolios id="0809"> <src link="http://www.gmail.com"></src> </portfolios> <portfolios id="0810"> <src link="http://www.codeproject.com></src> </portfolios> <portfolios id="0811"> <src link="http://www.xyz.com"></src> </portfolios> </portfolio> and check my backend coding. protected void imgbtnNext_Click(object sender, ImageClickEventArgs e) { //string crnturl = Request.Url.ToString(); XmlDocument doc=new XmlDocument(); XmlNode root = doc.LastChild; if (root) { imgbtnNext.Enabled = false; } else { string myurl = Request.QueryString.Get("id").ToString(); XmlDataSource xsd = new XmlDataSource(); xsd.DataFile = "~/App_Data/portfolio.xml"; xsd.XPath = "portfolio/portfolios[@id='" + myurl + "']/src"; GridView ds = new GridView(); ds.DataSource = xsd; ds.DataBind(); iframeprojects.Attributes.Add("src", ds.Rows[0].Cells[0].Text.ToString()); } }
Hmmm, seems a bit complicated. Why not loading the document and the use Xpath?
XmlDocument doc = new XmlDocument();
doc.Load("...");XmlNode oCurNode = doc.SelectSingleNodes("portfolio/portfolios[@id='" + myurl + "']/src");
iframeprojects.Attributes.Add("src", oCurNode.Attributes["link"].InnerText);Best would be to pass the id of the current node, so that you can find the next one. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Hmmm, seems a bit complicated. Why not loading the document and the use Xpath?
XmlDocument doc = new XmlDocument();
doc.Load("...");XmlNode oCurNode = doc.SelectSingleNodes("portfolio/portfolios[@id='" + myurl + "']/src");
iframeprojects.Attributes.Add("src", oCurNode.Attributes["link"].InnerText);Best would be to pass the id of the current node, so that you can find the next one. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
hi thanks Sebastian, Nut i didn't get how to get the next node value.
-
hi thanks Sebastian, Nut i didn't get how to get the next node value.
Extend the code as following to get the next node id:
XmlDocument doc = new XmlDocument();
doc.Load("...");XmlNode oCurNode = doc.SelectSingleNodes("portfolio/portfolios[@id='" + id + "']/src");
iframeprojects.Attributes.Add("src", oCurNode.Attributes["link"].InnerText);// get next node (this will be a portfolio)
XmlNode oNextNode = oCurNode.NextSibling;
// get the id attribute
string sNextId = oNextNode.Attributes["id"].InnerText;Then save the sNextId somewhere so that on the next button click you can use it. Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.