Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parsing XML from a web page

Posted on 2004-10-12
3
Medium Priority
?
145 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 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…
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…

670 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