xmldatasource in

Posted on 2007-10-16
Last Modified: 2013-11-07
In 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" >
Question by:ANAT2403
    LVL 4

    Expert Comment

    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.
    LVL 4

    Accepted Solution

    Something like

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

    XmlNode Node = Doc.SelectSingleNode(XPathExpression);
    return Node.InnerXml;

    Author Comment

    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.
    LVL 4

    Expert Comment

    Because the SiteMap is a very special thing indeed, it is built into the fabric of our pages. so we don't have to open it up and parse ourselves

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now