reading XML

D

davidjohnlong

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
 
A

Anthony Jones

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'"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top