Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

Parsing XML from a web page

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
bbies
Asked:
bbies
1 Solution
 
reginabCommented:
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
 
bbiesAuthor Commented:
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
 
ChenChenCommented:

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now