Solved

XmlTextReader screen scrape get xml element content

Posted on 2006-11-30
4
464 Views
Last Modified: 2013-11-19
Im trying to grab xml off a web page and get the content of one particular element.

i have a page xml.asp that outputs the following xml:

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="../quote_xml.css"?>
<quotes>
            <quote>
                        <exchange>XYZ</exchange>
                        <symbol>ABC</symbol>
                        <description>Lorem Ipsum</description>
                        <lastprice>32.500</lastprice>
                        <timestamp>
                                    <date>20061201</date>
                                    <time>105500</time>
                        </timestamp>
            </quote>
</quotes>

in my vb.net code i have this so far:

Imports System.XML

Dim xtr as New XmlTextReader("http://www.mypage.com/xml.asp")

xtr.MoveToContent()
xtr.MoveToElement("lastprice") 'error here!

'how can i get the lastprice element's content i.e. 32.500 ?
'i'm unsure of how to use the XmlTextReader's methods, can someone point out good examples of its usage?




0
Comment
Question by:VirusMinus
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
Comment Utility
Hi VirusMinus,

Check out: http://www.codeproject.com/vb/net/parsefilecode.asp

it has a good example on parsing xml.

Cheers,
Hillwaaa
0
 
LVL 30

Author Comment

by:VirusMinus
Comment Utility
Thanks, i saw that page already. any ideas on my particular problem. I'm thinking there's got to be a simpler way to do it as compared to what the page shows, just to get one element's content.
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 500 total points
Comment Utility
From that document, I'd say the easiest option for you is:

      Dim m_xmld = New XmlDocument
        'Load the Xml file
        m_xmld.Load("http://www.mypage.com/xml.asp")
        'Get the list of name nodes
        m_xmld.SelectNodes("/family/name")
        Dim m_nodelist As Xml.XmlNodeList
        m_nodelist = m_xmld.SelectNodes("/quotes/quote")
        Dim m_node As Xml.XmlNode
        'Loop through the nodes
        For Each m_node In m_nodelist
            MessageBox.Show(m_node.ChildNodes.Item(3).InnerText)
        Next
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Combobox, SelectedIndexChanged Get Index 2 21
How Can I fix my MouseHover Event? 14 26
Paging GridView 7 32
Get String split 5 31
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to count occurrences of each item in an array.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now