Solved

Parsing XML from a web page

Posted on 2004-10-12
3
134 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
Comment Utility
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
Comment Utility
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
Comment Utility

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

12 Experts available now in Live!

Get 1:1 Help Now