473,783 Members | 2,564 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 1642
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
2351
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
4023
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
2985
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
2200
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
1054
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
3084
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
3271
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
7223
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
9480
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
10315
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
10147
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...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5379
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.