Solved

Parsing XML from a web page

Posted on 2004-10-12
3
141 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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

830 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