Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to retrieve data from XML File

Status
Not open for further replies.

zishan876

Programmer
Mar 19, 2007
61
US
hi:
I have the following scenario:
Basically through my VB6 app, connection is made to my SQL Server to get addresses.
then URL is open and the url address is placed in which is actually an XML Web base file.

How do I get the data and bring it back to SQL Server for update to that record?

I did everything else but don't know how to do this part..
Code:
  <?xml version="1.0" ?> 
- <rdf:RDF xmlns:dc="[URL unfurl="true"]http://purl.org/dc/elements/1.1/"[/URL] xmlns:geo="[URL unfurl="true"]http://www.w3.org/2003/01/geo/wgs84_pos#"[/URL] xmlns:rdf="[URL unfurl="true"]http://www.w3.org/1999/02/22-rdf-syntax-ns#">[/URL]
- <geo:Point rdf:nodeID="aid65060998">
  <dc:description>22 W 74th St</dc:description> 
  <geo:long>-73.975720</geo:long> 
  <geo:lat>40.777796</geo:lat> 
  </geo:Point>
  </rdf:RDF>
I need the lat and long from this file... how do I get that
 
[tt][blue]'suppose the surl being the given pointing to the xml doc file[/blue]
Dim oparser As DOMDocument60 'add the reference
Dim slong As String 'storing longitude data
Dim slat As String 'storing latitude data
Dim bret As Boolean

Set oparser = New DOMDocument60
With oparser
.async = False
.validateOnParse = False
.resolveExternals = True
.setProperty "SelectionLanguage", "XPath"
.setProperty "SelectionNamespaces", "[ignore]xmlns:geo='[/ignore]"
End With

bret = oparser.Load([blue]surl[/blue])
If bret Then
slong = oparser.documentElement.selectSingleNode("//geo:long").Text
slat = oparser.documentElement.selectSingleNode("//geo:lat").Text
Else
'error loading the url
'decide what to return on slat and slong
End If
Set oparser = Nothing
[/tt]
 
thank you thank you thank you so much... you were very helpful
 
In such simple cases it is often just as useful to parse using String operations:
Code:
Private Sub ParseRDF(ByRef XML As String, _
                     ByRef ReturnLong As String, _
                     ByRef ReturnLat As String)
    Dim strParts() As String
    
    strParts = Split(Split(LCase$(Replace$(Replace$(XML, vbCr, ""), vbLf, "")), _
                           "<geo:long>")(1), _
                     "</geo:long>")
    ReturnLong = Trim$(strParts(0))
    strParts = Split(Split(strParts(1), "<geo:lat>")(1), "</geo:lat>")
    ReturnLat = Trim$(strParts(0))
End Sub
When things get even a little more complicated the benefits of using a generalized parser can outweigh its overhead of course.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top