Solved

Parsing XML from a web page

Posted on 2004-10-12
3
142 Views
Last Modified: 2010-05-02
How do parse a web page returned as xml and load a certain field from the xml page to a text box.  I want to do all of this behind the scenes, so the user only sees the value returned, never seeing the xml itself.

 I'm working with a web site that determines estimated freight charges, I provide the site with a URL that contains all of the information about the shipment and it returns an XML document with all of the estimated charges.  I need to grab the net freight charge and return it to the user's form.  I just don't know how to load the xml document to a recordset or something and parse out the <netfreightcharges> field from the xml document.

This is the field in the xml document that I need to return.
<netfreightcharges>335.83</netfreightcharges>

Thanks in advance.

0
Comment
Question by:bbies
[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
3 Comments
 
LVL 4

Expert Comment

by:reginab
ID: 12292069
this seems pretty vague could you be more specific? also this may be a question for the xml area.  are you trying to parse this xml with vb? check this out http://www.experts-exchange.com/Web/Web_Languages/XML/Q_21140317.html
hope that gets you started.
0
 

Author Comment

by:bbies
ID: 12292196
I figured this one out.  Here's the code.
==================================

Dim DestZip As String
Dim Weight As String
Dim Class As String


Private Sub cmdCalcFreight_Click()

Dim oDoc As New MSXML2.DOMDocument30
Dim currNode As IXMLDOMNode
DestZip = Trim(txtDestZip.Text)
Weight = Trim(txtWeight.Text)
Class = Trim(txtClass.Text)
 
    oDoc.async = False
    oDoc.Load "+++++URL OF XML DOCUMENT+++++"
   
    For Each currNode In oDoc.childNodes(1).childNodes(0).childNodes
        If currNode.nodeName = "netfreightcharges" Then
            lblFreight.Caption = currNode.Text
        End If
    Next
   
Set currNode = Nothing
Set oDoc = Nothing
End Sub
0
 
LVL 4

Accepted Solution

by:
ChenChen earned 250 total points
ID: 12295212

you could improve your code by using a bit of xpath,  like this:

'if there is only one <netfreightcharges> node in your xml doc:
set currNode = oDoc.selectSingleNode("//netfreightcharges")

'or, you have to use the full path,
'eg: if the xml document is structured as this:
'<root>
'<node1>
'<node2>
'<netfreightcharges>$$$</netfreightcharges>
'</node2>
'</node1>
'....
'</root>
' then:
set currNode = oDoc.selectSingleNode("root/node1/node2/netfreightcharges")

if not currNode is nothing then lblFreight = currNode.Text

'you don't have to loop through the xml...

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

752 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