XML file read

stratus

Active Member
Licensed User
Longtime User
Reading them is easy. They are just text files so open them with FileOpPen and read each line with FileRead.

Parsing them is a different matter. You will have to write that yourself!
Yes i mean parse the xml file.:signOops:
 

alfcen

Well-Known Member
Licensed User
Longtime User
You are welcome. If you prefer conventional methods, data embraced in an XML tag can be parsed like this:

B4X:
url = ParseXML(x, "<url>", "</url>")

Sub ParseXML(p, t1, t2)
  'Extracts a string embraced in t1 an t2 tags
  Dim l, r1, r2
  l = StrLength(t1)
  r1 = StrIndexOf(p, t1, 0)
  If r1 > 0 Then  'if the start tag is found then...
    r2 = StrIndexOf(p, t2, r1 + 1)  'look for the end tag
    p = SubString(p, r1 + l, r2 - r1 - l)  'extract the string between the tags
    Return p  'Return the wanted string
  End If   
End Sub

This would extract an URL embraced in, for example <url>http://www.server.com/</url> tags.
x is the string obtained with

B4X:
FileOpen(c1,"myfile.xml")
x = FileReadToEnd (c1)
FileClose(c1)

Best luck!
Robert
 

digitaldon37

Active Member
Licensed User
Longtime User
XML Parsing

I'm writing a program that retrieves weather data from one of the web services at webservicex.net; it sends an xml stream that contains single value tags (location data) and nested tags (for weather data)

This is the web service that I'm using: WebserviceX.NET :: Web Services

An XML reader library would be helpful, but until there is one I'm trying to use the Regex library to do it.

Attached is a work-in-progress that I put together to test extracting string(s) from an XML stream. Anyone else working with XML data?
 

Attachments

  • xmlTest.sbp
    3 KB · Views: 219

alfcen

Well-Known Member
Licensed User
Longtime User
Hi digitaldon37,

Thanks a lot for sharing this.

Attached please find code for global weather retrieved from the same source.
It employs only one library, namely http.dll.

Country names and cities may need to be checked against
WebserviceX.NET :: Web Services

I still prefer Wunderground's weather data, which in my believe is most
accurate, but unfortunately, not available in XML.
Example is here: alfcen - tenki

Cheers
Robert
 

Attachments

  • wxtest.zip
    31.2 KB · Views: 200
  • wx1.jpg
    wx1.jpg
    15 KB · Views: 205
  • wx2.jpg
    wx2.jpg
    16 KB · Views: 211

digitaldon37

Active Member
Licensed User
Longtime User
Thanks for the XML examples

alfcen, thanks for the XML example. I looked at your web site and saw that you have quite a few apps written in b4ppc.
 
Top