Solved

XmlTextReader screen scrape get xml element content

Posted on 2006-11-30
4
478 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18050475
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
ID: 18050729
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
ID: 18050818
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

695 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