Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2007, 06:41 AM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML problems - prefixes and asp.net

Hi can anyone help me I'm currently trying to use a rss feed from the yahoo weather site and manipulate it.

The issue i have is with the prefixes:

<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
....
<item>
...
<yweather:condition text="Mostly Cloudy" code="28" temp="15" date="Mon, 02 Jul 2007 8:50 am BST" />
</item>
</channel>
</rss>0

I'm having difficulty accessing the attributes within the yweather:conditon tag. Currently trying to use asp.net, can't seem to get to this tag or it's attributes.

Can anyone help? I would appreciate it, thanks in advance.

Gemma
 
Old July 2nd, 2007, 07:59 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you show what you have tried? There is help on accessing namespaced elements in the first post in this forum. If you need to bind prefixes to namespace URIs you either need to declare them on the XSLT or by using the NamespaceManager, depending on how you are working with the data.

--

Joe (Microsoft MVP - XML)
 
Old July 2nd, 2007, 09:28 AM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();
        XmlNodeList nodeList;

        doc.Load("rss.xml");

        //Create an XmlNamespaceManager for resolving namespaces.
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
        nsmgr.AddNamespace("yweather", "urn:samples");


        nodeList = doc.SelectNodes("/rss/channel/item/yweather:condition", nsmgr);


        foreach (XmlNode node in nodeList)
        {

            Response.Write(node.InnerText + "<br>");

        }
    }

if i use the above code, nothing is outputted, but if i remove the /yweather:condition then it does output. any ideas?

thanks
 
Old July 2nd, 2007, 09:43 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well yweather is mapped to http://xml.weather.yahoo.com/ns/rss/1.0 in the XML, not urn:samples.

--

Joe (Microsoft MVP - XML)
 
Old July 2nd, 2007, 09:50 AM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

that doesn't seem to make any difference???

 
Old July 2nd, 2007, 11:03 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Sorry but that should work, what code do you have now? Can you also post the rss XML so that I can see tthe structure more clearly?

--

Joe (Microsoft MVP - XML)
 
Old July 2nd, 2007, 12:03 PM
Registered User
 
Join Date: Jul 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, it seems to be working but how do i output at particular attribute?

thanks

Gemma

 
Old July 3rd, 2007, 01:56 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Code:
foreach (XmlNode node in nodeList)
{
  XmlElement weather = node as XmlElement;
  string description = weather.GetAttribute("text");
  Response.Write(description);          
}
--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
New to ASP.NET and lots of problems Lessa ASP.NET 1.0 and 1.1 Basics 7 April 29th, 2008 07:05 AM
Asp.net Logout problems hemal_301080 ASP.NET 1.0 and 1.1 Professional 1 August 6th, 2006 12:16 PM
Problems with debugging ASp.net ocabrera70 ASP.NET 2.0 Basics 1 March 1st, 2006 03:49 PM
Parse XML doc using VB.NET into ASP.NET page kwilliams Classic ASP XML 17 November 11th, 2005 10:42 AM
New to ASP.NET w/ C# and having problems digitaltoddy BOOK: Beginning ASP.NET 1.0 1 September 20th, 2004 07:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.