SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XPath problem when XML tag has a prefix

    I am using the Xmldatasource Control and XPathNavigator (in code behind) to parse an XML file for output on a website. For the output I am using a Repeater doing something like this:

    <asp:XmlDataSource ID="RssFeed" runat="server" DataFile="example.xml" XPath="/rss/channel/item[position()<10]"></asp:XmlDataSource>
    <asp:Repeater ID="repeater1" runat="server" DataSourceID="RssFeed" OnItemDataBound="repeater1_ItemDataBound">
    <ItemTemplate>
    <p><&#37;# XPath("title") %></p>
    <p><%# XPath("description") %></p>
    </ItemTemplate>
    </asp:Repeater>

    That works fine until the one of the XML tags has a prefix like <dc:creator>.
    If I try <p><%# XPath("dc:creator") %></p>, then I get this error message:
    Exception Details: System.Xml.XPath.XPathException: Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function.

    How would I get at a tag with a prefix?

  2. #2
    SitePoint Evangelist
    Join Date
    Apr 2008
    Location
    Dublin, Ireland
    Posts
    461
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Addict frankdux's Avatar
    Join Date
    Apr 2004
    Location
    Ashland, North Carolina
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem with that is I was using the XMLDataSource control and apparently it doesn't support namespaces. Seemed like it was perfect way to parse XML when using .NET 2.0. Now I have to rethink it.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •