Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 536
  • Last Modified:

xmldatasource in asp.net

In ASP.net 2.0 with C# I have an xmldatasource control. when this control is bind to a repeater I can get the data form nodes by XPath.
I want to have a span and in this span to show the content of the first node in the xml file(title).
how do I do it?

If I have a sitemap I succeed do this thing like this:
<span class="txt"><%=sitemaptemp.Provider.RootNode.Title%></span>
<asp:SiteMapDataSource ID="sitemaptemp" SiteMapProvider="sitemaptempProvider"
         runat="server" StartingNodeOffset="0" ShowStartingNode="false"  />
but if I have an XML I don't know how to do it? THis is the definition for the XML:
     <asp:XmlDataSource ID="XmlDSCategory" runat="server" DataFile="~/App_Data/XMLCategory.xml" >
               </asp:XmlDataSource>
thankyou
Anat
0
ANAT2403
Asked:
ANAT2403
  • 3
1 Solution
 
S31B1Commented:
I'm assuming your talking about accessing the data from outside of a DataBound control?

If so then your XmlDataSource will not provide you anything.

You are going to need to code a helper function in your code behind to load your xml file and extract the value you need.
0
 
S31B1Commented:
Something like

public string GetNodeInnerXml(string relativeXmlDocFileName, string XPathExpression)
{
XmlDocument Doc = new XmlDocument();

Doc.Load(Server.MapPath(relativeXmlDocFileName));
XmlNode Node = Doc.SelectSingleNode(XPathExpression);
return Node.InnerXml;
}
0
 
ANAT2403Author Commented:
Hi,
I ment what you said but why if it comes from web.sitemap which is also an XML it is possible and in regular XML not.
Anat
0
 
S31B1Commented:
Because the SiteMap is a very special thing indeed, it is built into the fabric of our asp.net pages. so we don't have to open it up and parse ourselves
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now