Transforming XML and display as a label in ASPX page

Discussion in 'ASP .Net Web Services' started by Guest, Oct 8, 2004.

  1. Guest

    Guest Guest

    Guest, Oct 8, 2004
    #1
    1. Advertising

  2. wrote:


    > Can I get XML data from an external XML file loaded in an ASPX page to be
    > displayed as a "Label"?
    > I don't want to use the XML control <asp:xml>, but a label in order to
    > display the source.
    >
    > Here comes the example XML file:
    > http://webservices.amazon.de/onca/x...kup&ItemId=B0001BXYQ0&ResponseGroup=SalesRank
    >
    > I want to put the SalesRank value into my label.


    Here is an example using XPathDocument to read out the SalesRank:

    <%@ Page Language="C#" Debug="True" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Import Namespace="System.Xml.XPath" %>
    <script runat="server">
    void Page_Load () {
    XPathDocument amazonResult = new
    XPathDocument(@"http://webservices.amazon.de/onca/xml?Service=AWSECommerceService&SubscriptionId=19JR8DEMH9649D8NAY02&Operation=ItemLookup&ItemId=B0001BXYQ0&ResponseGroup=SalesRank");
    XPathNavigator xpathNavigator = amazonResult.CreateNavigator();
    XPathExpression xpathExpression =
    xpathNavigator.Compile(@"/am:ItemLookupResponse/am:Items/am:Item/am:SalesRank/text()");
    XmlNamespaceManager namespaceManager = new
    XmlNamespaceManager(xpathNavigator.NameTable);
    namespaceManager.AddNamespace("am",
    "http://xml.amazon.com/AWSECommerceService/2004-08-01");
    xpathExpression.SetContext(namespaceManager);
    XPathNodeIterator nodeIterator = xpathNavigator.Select(xpathExpression);
    if (nodeIterator.MoveNext()) {
    Label1.Text = nodeIterator.Current.Value;
    }
    }
    </script>
    <form runat="server">
    <asp:Label runat="server" id="Label1" />
    </form>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 9, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dwhitford
    Replies:
    0
    Views:
    372
    dwhitford
    May 14, 2004
  2. Krista Lemieux

    Transforming XML with XSL to String

    Krista Lemieux, Aug 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    461
    Steve Flitcroft
    Aug 10, 2004
  3. Roger Varley

    Design Query - Transforming XML

    Roger Varley, Feb 3, 2005, in forum: Java
    Replies:
    0
    Views:
    344
    Roger Varley
    Feb 3, 2005
  4. CSharpner
    Replies:
    0
    Views:
    1,015
    CSharpner
    Apr 9, 2007
  5. Knut Krueger
    Replies:
    8
    Views:
    264
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page