473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

reading XML

Hi,

I'm currently trying to display a XML file within a ASP page, although
get the following error when trying to select one of the notes... the
node is called: <content:encoded>

This is the error
Reference to undeclared namespace prefix: 'content'.

This is my code

<%@ Language="VBScript" %>
<html lang="en">
<head>
<title>Some feeds</title>
<script runat="server" language="VBScript">
Sub OutputFeed (feedURL)
Dim XmlDocument
Set XmlDocument = Server.CreateObject("Msxml2.DOMDocument.4.0")
XmlDocument.setProperty "ServerHTTPRequest", true
XmlDocument.async = False
Dim Loaded
Loaded = XmlDocument.load(feedURL)
If Loaded Then
Dim Items, Item, Title, Link, Description, TitleText,
DescriptionText, LinkURL, Content2, Contenttext
Set Items = XmlDocument.selectNodes("//item")
Response.Write "<p>Feed from " & feedURL & " has currently " &
Items.Length & " items.</p>" & VbCrLf
Response.Write "<ul>" & VbCrLf
For Each Item in Items
Set Title = Item.selectSingleNode("title/text()")
If Title Is Nothing Then
TitleText = ""
Else
TitleText = Title.data
End If
Set Link = Item.selectSingleNode("link/text()")
If Link Is Nothing Then
LinkURL = ""
Else
LinkURL = Trim(Link.data)
End If
Set Content2 = Item.selectSingleNode("content:encoded")
If Content2 Is Nothing Then
Contenttext = ""
Else
Contenttext= Trim(Content2.data)
End If
Set Description = Item.selectSingleNode("description/text()")
If Description Is Nothing Then
DescriptionText = ""
Else
DescriptionText = Description.data
End If
Response.Write "<li><a href=""" & LinkURL & """>" & TitleText &
": " & DescriptionText & "</a></li>" & VbCrLf
response.Write contexttext
Next
Response.Write "</ul>" & VbCrLf
End If
End Sub
</script>
</head>
<body>

<h1>Some feeds</h1>

<%
OutputFeed("http://www.biblegateway.com/usage/votd/rss/votd.rdf?31")
OutputFeed("http://rss.news.yahoo.com/rss/elections")
OutputFeed("http://www.cbsnews.com/feeds/rss/main.rss")
OutputFeed("http://rss.cnn.com/rss/si_topstories.rss")
%>

</body>
</html>
Thank you for your help

Jul 4 '06 #1
1 3132

<da***********@googlemail.comwrote in message
news:11**********************@a14g2000cwb.googlegr oups.com...
Hi,

I'm currently trying to display a XML file within a ASP page, although
get the following error when trying to select one of the notes... the
node is called: <content:encoded>

This is the error
Reference to undeclared namespace prefix: 'content'.
The problem is that the document namespaces and the selection namespaces are
separate.

In order to select a node in a another namespace you need to add the
namespace to the selection namespaces.

This is done through a second level property called, believe it or not,
"SelectionNamespaces"

Assuming you have in the document the an alias declared like this:-

<someToplevelNode xmlns:content="urn:thingy:stuff">

or

<someToplevelNode xmlns:content="http://somecompay.com/ournamespace">

then your code should contain this before you attempt the select:-

XmlDocument.setProperty "SelectionNamespaces",
"xmlns:content='http://somecompay.com/ournamespace'"

This is my code

<%@ Language="VBScript" %>
<html lang="en">
<head>
<title>Some feeds</title>
<script runat="server" language="VBScript">
Sub OutputFeed (feedURL)
Dim XmlDocument
Set XmlDocument = Server.CreateObject("Msxml2.DOMDocument.4.0")
XmlDocument.setProperty "ServerHTTPRequest", true
XmlDocument.async = False
Dim Loaded
Loaded = XmlDocument.load(feedURL)
If Loaded Then
Dim Items, Item, Title, Link, Description, TitleText,
DescriptionText, LinkURL, Content2, Contenttext
Set Items = XmlDocument.selectNodes("//item")
Response.Write "<p>Feed from " & feedURL & " has currently " &
Items.Length & " items.</p>" & VbCrLf
Response.Write "<ul>" & VbCrLf
For Each Item in Items
Set Title = Item.selectSingleNode("title/text()")
If Title Is Nothing Then
TitleText = ""
Else
TitleText = Title.data
End If
Set Link = Item.selectSingleNode("link/text()")
If Link Is Nothing Then
LinkURL = ""
Else
LinkURL = Trim(Link.data)
End If
Set Content2 = Item.selectSingleNode("content:encoded")
If Content2 Is Nothing Then
Contenttext = ""
Else
Contenttext= Trim(Content2.data)
End If
Set Description = Item.selectSingleNode("description/text()")
If Description Is Nothing Then
DescriptionText = ""
Else
DescriptionText = Description.data
End If
Response.Write "<li><a href=""" & LinkURL & """>" & TitleText &
": " & DescriptionText & "</a></li>" & VbCrLf
response.Write contexttext
Next
Response.Write "</ul>" & VbCrLf
End If
End Sub
</script>
</head>
<body>

<h1>Some feeds</h1>

<%
OutputFeed("http://www.biblegateway.com/usage/votd/rss/votd.rdf?31")
OutputFeed("http://rss.news.yahoo.com/rss/elections")
OutputFeed("http://www.cbsnews.com/feeds/rss/main.rss")
OutputFeed("http://rss.cnn.com/rss/si_topstories.rss")
%>

</body>
</html>
Thank you for your help

Jul 4 '06 #2

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

Similar topics

0
by: Andy | last post by:
Hi, In the code below (not pretty I know but it's an early version :-P) I'm having problems reading the data object back in. If I move the reading code to immediately after the section where it...
6
by: Raymond Hettinger | last post by:
Found in a pamphlet at a pre-school: --------------------------------------- Reading improves vocabulary Reading raises cultural literacy through shared knowledge Reading develops writing skills...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
24
by: Hendrik Schober | last post by:
Hi, I have a 'std::istream' and need to read its whole contents into a string. How can I do this? TIA; Schobi
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
4
by: Gaijinco | last post by:
I had a file named nap.in which looks like this: 4 10:00 12:00 Lectures 12:00 13:00 Lunch, like always. 13:00 15:00 Boring lectures... 15:30 17:45 Reading 4 10:00 12:00 Lectures 12:00 13:00...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.