473,778 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing XML elements by name with ASP

I am using MSXML 4.0

I am grabbing numerous RSS News Feeds and trying to parse the data and
read it into a dB. The problem is that the RSS News feeds are not all
the same when tunneled down in the item element.

They ALL contain the nodes: title, description, link and pubDate. But
they come in all different orders and have other child nodes sandwiched
among the ones I am after.

<channel>
<item>
<title>
<description>
<link>
<pubDate>
example: http://rss.news.yahoo.com/rss/elections
example: http://www.cbsnews.com/feeds/rss/main.rss
example: http://rss.cnn.com/rss/si_topstories.rss
My code issue is;

When looping through the recordset I have to reference the childnode
numerically ie. item.childnodes .item(0).text,
item.childnodes .item(1).text, item.childnodes .item(2).text

But because I am trying to use the same code for every feed I want to
access the childnodes by their names: item.childnodes .item(title).te xt,
item.childnodes .item(descripti on).text, item.childnodes .item(link).tex t
because in some feeds 0=title and in others 0=link etc etc...

I have spent three days searching the net and have not found anything.

Does anyone have a way to do this?

For those that want to give me their .Net solution I am sad to say it
must be done using ASP/ADO.

Please show me the way!!

|
-----O--------> E

|

-Gordon

glearATgmail.co m

Jul 20 '05 #1
3 1732
My bad. Don't use glearATgmail.co m it is old. Just reply to this
post. I have it starred. thx!!

Jul 20 '05 #2
go*********@gma il.com wrote:
I am using MSXML 4.0

I am grabbing numerous RSS News Feeds and trying to parse the data and
read it into a dB. The problem is that the RSS News feeds are not all
the same when tunneled down in the item element.

They ALL contain the nodes: title, description, link and pubDate. But
they come in all different orders and have other child nodes
sandwiched among the ones I am after.

<channel>
<item>
<title>
<description>
<link>
<pubDate> .... For those that want to give me their .Net solution I am sad to say it
must be done using ASP/ADO.

I'm not sure how you would translate this to ASP, but this is how I
would do using Expat parser and Bash shell:

data () # Usage: data data
{
tmp=$1
set -- ${XML_ELEMENT_S TACK[*]|=+([a-zA-Z])}
if [[ $2.$3 == item.channel ]]; then
case $1 in
title|descripti on|link|pubDate ) strcpy $1 $tmp ;;
esac
fi
}
end () # Usage: end tag
{
[[ $1 == item ]] && declare -p title description link pubDate
}
xml -d data -e end '<channel> ... </channel>'

--
William Park <op**********@y ahoo.ca>, Toronto, Canada
Slackware Linux -- because it works.

Jul 20 '05 #3


go*********@gma il.com wrote:
I am using MSXML 4.0

I am grabbing numerous RSS News Feeds and trying to parse the data and
read it into a dB. The problem is that the RSS News feeds are not all
the same when tunneled down in the item element.

They ALL contain the nodes: title, description, link and pubDate. But
they come in all different orders and have other child nodes sandwiched
among the ones I am after.

<channel>
<item>
<title>
<description>
<link>
<pubDate>
example: http://rss.news.yahoo.com/rss/elections
example: http://www.cbsnews.com/feeds/rss/main.rss
example: http://rss.cnn.com/rss/si_topstories.rss
My code issue is;

When looping through the recordset I have to reference the childnode
numerically ie. item.childnodes .item(0).text,
item.childnodes .item(1).text, item.childnodes .item(2).text


You need to learn XPath and use selectNodes/selectSingleNod e to find the
right elements and their content, the following shows how to do that
with VBScript in ASP using MSXML 4 and selectNodes, selectSingleNod e. It
is also possible to solve that without XPath using getElementsByTa gName
as needed.

Watch out for line breaks introduced by the post but not allowed in
vbscript:

<%@ Language="VBScr ipt" %>
<html lang="en">
<head>
<title>Some feeds</title>
<script runat="server" language="VBScr ipt">
Sub OutputFeed (feedURL)
Dim XmlDocument
Set XmlDocument = Server.CreateOb ject("Msxml2.DO MDocument.4.0")
XmlDocument.set Property "ServerHTTPRequ est", true
XmlDocument.asy nc = False
Dim Loaded
Loaded = XmlDocument.loa d(feedURL)
If Loaded Then
Dim Items, Item, Title, Link, Description, TitleText,
DescriptionText , LinkURL
Set Items = XmlDocument.sel ectNodes("//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.selectSing leNode("title/text()")
If Title Is Nothing Then
TitleText = ""
Else
TitleText = Title.data
End If
Set Link = Item.selectSing leNode("link/text()")
If Link Is Nothing Then
LinkURL = ""
Else
LinkURL = Trim(Link.data)
End If
Set Description = Item.selectSing leNode("descrip tion/text()")
If Description Is Nothing Then
DescriptionText = ""
Else
DescriptionText = Description.dat a
End If
Response.Write "<li><a href=""" & LinkURL & """>" & TitleText &
": " & DescriptionText & "</a></li>" & VbCrLf
Next
Response.Write "</ul>" & VbCrLf
End If
End Sub
</script>
</head>
<body>

<h1>Some feeds</h1>

<%
OutputFeed("htt p://rss.news.yahoo. com/rss/elections")
OutputFeed("htt p://www.cbsnews.com/feeds/rss/main.rss")
OutputFeed("htt p://rss.cnn.com/rss/si_topstories.r ss")
%>

</body>
</html>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #4

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

Similar topics

1
4076
by: DU | last post by:
Assuming you have a typical form built in this manner: <form action="..."> <p><input id="idInputText" name="nameInputText" type="text" size="20"></p> <p><input id="idCheckbox" name="nameCheckbox">optional</p> <p><input id="idRadio1" name="nameRadio">yes<input id="idRadio2" name="nameRadio">no</p> <p><select id="idSelect" name="nameSelect"><option value="a">a</option><option value="b">b</option><option value="c">c</option></select></p>
5
2132
by: Rune Runnestø | last post by:
How do I focus the cursor in the input field 'numberField' when accessing this jsp-file (or html-file) ? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head>
6
2746
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is called "form1", and I have selects called "PORTA", "PORTB" ... etc...
19
10553
by: k.karthikit | last post by:
Hello all, In some hidden variable (<input type="hidden" name="hiddenId" value="test" /> ,i stored some value.I accessed the value "test" using var id = document.getElementById( 'hiddenId' ); It is working fine in IE. But in Mozilla Firefox , null value is returned.Is there any way to use hidden variables compatible to browsers......?
1
2604
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). When a field gets added, a link that opens a popup window is next to it. The popup is opened and has the name of the parent element it should change in it. The user can use the popup to get a list of results. In the results I would like them...
2
2134
by: Gerald Aichholzer | last post by:
Hello NG, I have the following XML (simplified) having a variable number of v-elements: <record> <field name="parameter"> <v0>paramname0</v0> <v1>paramname1</v1> <v2>paramname2</v2>
7
3821
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a database search that I am unable to figure out how to access. (The search is implemented in Php/MySQL.) The user enters search values for: name, address1, city, .... etc., ..... and for each of these they also select whether the search should...
6
10424
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to group by using a two dimensional array. <form name=msgs>
3
10522
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I can get at the value using the array method, the getelements by id method, and the bracket-with-the-element-name in it method. But the dot notation doesn't work, in firefox, in the function (which i have in the head).
5
2883
by: Paul Brettschneider | last post by:
Hello, I have a global static array of structs and want to access a given element using an identifier. I don't want to use the element subscript, because it will change if I insert elements before the element I want to access. In assembler I would simply add a label in front of the element, but this doesn't work in C++. The following programm snippet might explain what I want to do:
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
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
10292
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...
1
10061
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,...
1
7471
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
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5368
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
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.