Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP XML Using ASP 3 and XML. See also the XML category for more XML discussions not relating to ASP. NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old July 28th, 2005, 03:42 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, well this is what I've got.

XML doc:
<ealerts>
    <alert>
        <title>eAlert - Title #1</title>
        <rss_url>#</rss_url>
        <link>#</link>
        <image_url>http://SERVER/DIRECTORY/images/gif/ealert_title1.gif</image_url>
        <width>49</width>
        <height>48</height>
        <status>active</status>
    </alert>
    <alert>
        <title>eAlert - Title #2</title>
        <rss_url>#</rss_url>
        <link>#</link>
        <image_url>http://SERVER/DIRECTORY/images/gif/ealert_title2.gif</image_url>
        <width>49</width>
        <height>48</height>
        <status>active</status>
    </alert>

</ealerts>
XMLDocument method:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Xml" %>
<script runat="server">
'Pull in eAlerts data
Sub Main()
    Dim m_xmld As XmlDocument
    Dim m_nodelist As XmlNodeList
    Dim m_node As XmlNode
    'Create the XML Document
    m_xmld = New XmlDocument()
    'Load the Xml file
    m_xmld.Load("http://SERVER/DIRECTORY/docs/xml/ealerts.xml")
    'Get the list of name nodes
    m_nodelist = m_xmld.SelectNodes("/ealerts/alert")
    'Loop through the nodes
    For Each m_node In m_nodelist
      Dim titleValue = m_node.ChildNodes.Item(0).InnerText
      Dim rss_urlValue = m_node.ChildNodes.Item(1).InnerText
      Dim linkValue = m_node.ChildNodes.Item(2).InnerText
      Dim image_urlValue = m_node.ChildNodes.Item(3).InnerText
      Dim widthValue = m_node.ChildNodes.Item(4).InnerText
      Dim heightValue = m_node.ChildNodes.Item(5).InnerText
      Dim statusValue = m_node.ChildNodes.Item(6).InnerText
      'Get the Gender Attribute Value
      'Dim genderAttribute = m_node.Attributes.GetNamedItem("gender").Value

      'Write Result to the Console
      Response.Write("<strong>eAlert</strong><br />Title: " & titleValue & _
      " RSS URL: " & rss_urlValue & _
      " Link: " & linkValue & _
      " Image URL: " & image_urlValue & _
      " Width: " & widthValue & _
      " Height: " & heightValue & _
      " Status: " & statusValue)

    Next
End Sub
</script>
The good news is that no errors are returned, but the bad news is neither are any results...just a blank page. I'm not sure why that is, because the properties & syntax appear to be correct. If you see anything that I'm obviously missing, please let me know. I'll just keep on testing it out in the meantime.

KWilliams
Reply With Quote
  #12 (permalink)  
Old July 28th, 2005, 03:51 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Are you sure that http://SERVER/DIRECTORY/docs/xml/ealerts.xml results in a valid document that your web server is allowed to read?

Your code runs fine on my machine....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Mosquito Song by Queens of the Stone Age (Track 15 from the album: Songs For The Deaf) What's This?
Reply With Quote
  #13 (permalink)  
Old July 28th, 2005, 04:12 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It should, but since I'm doing all of this on an internal test-server, that could be possible. I'll check with my Network Administrator tomorrow morning about making sure that I have Read writes to that directory. But I'm not sure why I wouldn't, as I've been testing other things on that directory that requires read & write access with success.

Thanks for testing it out on your machine. That helps me to know that it could be a problem with the security vs. the code.

KWilliams
Reply With Quote
  #14 (permalink)  
Old July 28th, 2005, 04:50 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Would you mind telling me exactly how you tested the code out that I included with my previous post? I even tried creating a copy of the XML file into the same directory as the ASPX file with no success. I just can't figure out why it's working for you and not for me. How frustrating...

KWilliams
Reply With Quote
  #15 (permalink)  
Old July 28th, 2005, 05:02 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

I must admit I cheated a bit by moving this code into a Visual Studio Project with a code behind file. This may lead you to believe that this code does only work with Visual Studio, but I ensure you that's not the case.

The one thing that I changed, apart from moving the @Import to Imports statements in my code behind file, was drop the Main method and instead dump your code in the Page_Load of my page.

That is also probably causing this code not to run on your machine. In the ASP.NET world, Main is not a magical name for a method. Instead of Main you could have used Imar() or KWilliams() or whatever. So, basically, the framework treats this as a normal method and waits for code that triggers it.

To run the code when the page loads, you need to add it to the Page_Load method. In Visual Studio .NET you can declare that method like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' Code here

End Sub

However, in the Web Matrix, I think the AutoEventWireUp or whatever it is called is on by default, so you may get away with just Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

So, move your code to a method that is called at run-time and see if that makes a difference....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: 06 - Monsters In The Parasol by Queens of the Stone Age (Track 6 from the album: Rated R) What's This?
Reply With Quote
  #16 (permalink)  
Old July 28th, 2005, 05:10 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallelujah...it worked. Here's my final code:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Xml" %>
<script runat="server">

    'Pull in eAlerts data

    Sub Page_Load
        If Not Page.IsPostBack then
         Dim m_xmld As XmlDocument
         Dim m_nodelist As XmlNodeList
         Dim m_node As XmlNode
         'Create the XML Document
         m_xmld = New XmlDocument()
         'Load the Xml file
         m_xmld.Load("http://SERVER/DIRECTORY/docs/xml/ealerts.xml")
         'Get the list of name nodes
         m_nodelist = m_xmld.SelectNodes("/ealerts/alert")
         'Loop through the nodes
         For Each m_node In m_nodelist
           Dim titleValue = m_node.ChildNodes.Item(0).InnerText
           Dim rss_urlValue = m_node.ChildNodes.Item(1).InnerText
           Dim linkValue = m_node.ChildNodes.Item(2).InnerText
           Dim image_urlValue = m_node.ChildNodes.Item(3).InnerText
           Dim widthValue = m_node.ChildNodes.Item(4).InnerText
           Dim heightValue = m_node.ChildNodes.Item(5).InnerText
           Dim statusValue = m_node.ChildNodes.Item(6).InnerText
           'Get the Gender Attribute Value
           'Dim genderAttribute = m_node.Attributes.GetNamedItem("gender").Value

           'Write Result to the Console
           Response.Write("<strong>eAlert</strong><br />" & _
           "Title: " & titleValue & _
           " RSS URL: " & rss_urlValue & _
           " Link: " & linkValue & _
           " Image URL: " & image_urlValue & _
           " Width: " & widthValue & _
           " Height: " & heightValue & _
           " Status: " & statusValue)
         Next
   End If
    End Sub

</script>
...and it works like a charm. Thanks SO MUCH for your patient, thorough, and clearly wonderful help. You've been a great resource during this frustrating process, and I REALLY appreciate it. This forum is VERY lucky to have you as a member, and I'm not just saying that:)

KWilliams
Reply With Quote
  #17 (permalink)  
Old July 28th, 2005, 05:16 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,957
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

You're welcome. Glad it's all working now.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Government Flu by Dead Kennedys (Track 1 from the album: Plastic Surgery Disasters + In God We Trust) What's This?
Reply With Quote
  #18 (permalink)  
Old November 11th, 2005, 10:42 AM
Registered User
 
Join Date: Nov 2005
Location: Tampa, FL, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

err.... can we use XSLT instead of loading of XMLDocument and then walking thru the document tree? with XSLT i guess you don't have to do much coding and then if you change your mind to display the content in different format you can always go back to the xsl file and change it right?

<Programerror>Vijay.Patil</Programerror>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Use JavaScript in an ASP.NET/VB page kwilliams ASP.NET 2.0 Professional 5 January 14th, 2008 03:30 PM
parse error xml load document asp.net academics2006 ASP.NET 1.0 and 1.1 Basics 0 March 13th, 2006 03:21 PM
Newbie: Calling a VB doc from ASP.NET kwilliams Classic ASP Basics 2 August 31st, 2005 10:10 AM
How can I call a vb.net Exe from an asp.net page? jorevil Classic ASP Basics 0 October 1st, 2003 12:34 PM



All times are GMT -4. The time now is 12:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.