XML file read

Discussion in 'Questions (Windows Mobile)' started by stratus, Dec 2, 2007.

  1. stratus

    stratus Active Member Licensed User

    Is there any way to read xml files with basic4ppc;
     
  2. agraham

    agraham Expert Licensed 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!
     
  3. stratus

    stratus Active Member Licensed User

    Yes i mean parse the xml file.:signOops:
     
  4. alfcen

    alfcen Well-Known Member Licensed User

  5. stratus

    stratus Active Member Licensed User

    Very useful.Thank's
     
  6. alfcen

    alfcen Well-Known Member Licensed User

    You are welcome. If you prefer conventional methods, data embraced in an XML tag can be parsed like this:

    Code:
    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

    Code:
    FileOpen(c1,"myfile.xml")
    x = FileReadToEnd (c1)
    FileClose(c1)
    Best luck!
    Robert
     
  7. digitaldon37

    digitaldon37 Active Member Licensed 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?
     

    Attached Files:

  8. alfcen

    alfcen Well-Known Member Licensed 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
     

    Attached Files:

  9. digitaldon37

    digitaldon37 Active Member Licensed 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.
     
Loading...