473,703 Members | 3,125 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Highly annoying namespace problem

I've the following code, taken from
http://msdn.microsoft.com/library/de...ml02172003.asp
to select a node from RSS file.
However, I'm always getting a null returning for the SelectSingleNod e(),
when trying to load a RSS 1.0 document, (which has a default namespace)
why?

if(feed.Documen tElement.LocalN ame.Equals("RDF ") &&
feed.DocumentEl ement.Namespace URI.Equals("htt p://www.w3.org/1999/02/22-rdf-s
yntax-ns#"))

{

NamespaceUri = "http://purl.org/rss/1.0/";

}

else if(feed.Documen tElement.LocalN ame.Equals("rss "))

{

NamespaceUri = feed.DocumentEl ement.Namespace URI;

}

else

{

throw new RssFeedExceptio n(ResourceFetch er.GetException ("Illegal feed"));

}

XmlNamespaceMan ager nsMgr = new XmlNamespaceMan ager(feed.NameT able);

nsMgr.AddNamesp ace("rss",Names paceUri);

node = feed.SelectSing leNode("//rss:channel/title",nsMgr);//Select feed's
title
//node = feed.SelectSing leNode("//rss:channel/rss:title",nsMg r);//Doesn't
work as well!!!
if(node!=null)//It's ALWAYS null if there is a default namespace!

title = node.InnerText;

Nov 12 '05 #1
2 1637
Ayende Rahien wrote:
However, I'm always getting a null returning for the SelectSingleNod e(),
when trying to load a RSS 1.0 document, (which has a default namespace)
why?


Which document are you trying to load?
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
ru
I know your frustration, as I myself struggled with this
for weeks and weeks...
Here's how you do it:
dim rss as New XmlTextReader(U RL)
While rss.Read()
If rss.NodeType = XmlNodeType.Ele ment Then
Select Case rss.Name.ToLowe r()
Case "item"
strItem = rss.ReadString( )
Case "pubdate"
strDate = rss.ReadString( )
Case "dc:date"
strDate = rss.ReadString( )
etc.
end While

-----Original Message-----
I've the following code, taken from
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnexxml/html/xml02172003.aspto select a node from RSS file.
However, I'm always getting a null returning for the SelectSingleNod e(),when trying to load a RSS 1.0 document, (which has a default namespace)why?

if(feed.Docume ntElement.Local Name.Equals("RD F") &&
feed.DocumentE lement.Namespac eURI.Equals ("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))

{

NamespaceUri = "http://purl.org/rss/1.0/";

}

else if(feed.Documen tElement.LocalN ame.Equals("rss "))

{

NamespaceUri = feed.DocumentEl ement.Namespace URI;

}

else

{

throw new RssFeedExceptio n(ResourceFetch er.GetException ("Illegal feed"));
}

XmlNamespaceMa nager nsMgr = new XmlNamespaceMan ager (feed.NameTable );
nsMgr.AddNames pace("rss",Name spaceUri);

node = feed.SelectSing leNode ("//rss:channel/title",nsMgr);//Select feed'stitle
//node = feed.SelectSing leNode ("//rss:channel/rss:title",nsMg r);//Doesn'twork as well!!!
if(node!=nul l)//It's ALWAYS null if there is a default namespace!
title = node.InnerText;

.

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2337
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a similar name to the table. Rather than making a long Select Case that could become obsolete if lookup tables are added and the source table of the ListBox is edited I came up with this code.) This code works but of course it gives me build...
6
4017
by: rbazinet | last post by:
I have a VS 2003 C# project, web app with a bunch of DLL's. When I compile my project I often times get this message: Unexpected error creating debug information file 'C:\DevProjects\Allstar Admin\Allstar.Common.DataAccess\obj\Debug\Allstar.Common.DataAccess.PDB' -- 'C:\DevProjects\Allstar Admin\Allstar.Common.DataAccess\obj\Debug\Allstar.Common.DataAccess.pdb: The process cannot access the file because it is being used by another...
3
2981
by: Chris Mantoulidis | last post by:
I posted this here one day ago but it seems like it hasn't been put up for some unknown reason. That gives me a chance to say things a bit better in this post. 1st of all let's desribe the problem: In ParamGenerate() I want to find all whitespaces before a certain point in one string. Thus I use the string::find() function. However it seems like this function ignores some whitespaces :/ This is really weird and I need your help. Okay...
15
2189
by: 50295 | last post by:
Hi everyone, This one is better experienced than explained, so I'm including a code sample below. Please and save (as an html file) and view with NN or Firefox (or maybe even Mozilla), and then view. When loaded: (1.) Place the mouse over "Top Menu" item. (The menu opens) (2.) Move to any of the sub-menu items. (3.) Click on the left or right (but NOT on the text) of the current
5
1050
by: Ioannis Vranos | last post by:
Why does this annoying thing happen? #include <windows.h> #using <mscorlib.dll> using namespace System; using namespace System::Windows::Forms;
4
3082
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which leads to a secondary problem involving php's __autoload feature. Since you cannot specify a namespace when calling a class that may not have been included, you are forced to store all of your classes in the same folder in your file system. This...
6
3270
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls to the function in the container. I allocate (and free in c) arrays to get garbage collection in both C and C#. After a few seconds I get an exception. I assume GarbageCollector moves the delegate (or collects is) and when I don't find it in C...
84
7189
by: braver | last post by:
Is there any trick to get rid of having to type the annoying, character-eating "self." prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to use Ruby anywhere speed is not crucial especially for @ prefix is better- looking than self. But things grow -- is there any metaprogramming tricks or whatnot we can throw on the self? Cheers,
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9246
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9112
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7856
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4425
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4680
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2440
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2058
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.