Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

read and parse an xml file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    read and parse an xml file

    attached is an events.xml file and xbasic code.
    When you open the xml in notepad it opens as one continuous line.
    I need to read the XML file and start a new line when there is a
    <event> or after </event>

    I can write the xml file to a table but only after I manually open in notepad, add line breaks and then save.
    The attached code will write the xml file to a table if each event_id is on a separate line.

    Any help would be appreciated.
    Thanks
    Charlie Crimmel

    #2
    Re: read and parse an xml file

    "What's New in V9" has an extensive section on parsing XML with A5.
    -Steve
    sigpic

    Comment


      #3
      Re: read and parse an xml file

      Charlie,

      I was also going to suggest the XML parser as an other option. As well as the stringscanner object.

      But...
      To answer your question directly. To get each event on its own line you could use the following
      Code:
      xml_data = file.to_string("YourFilename")
      
      xml_data = stritran(xml_data,"</event><event>","</event><event>"+crlf())
      At this point you could write the data back to a file So that your current code can use it. But since you now have it in a variable I would just use the text in the variable. You would need to make a few changes to use it but I will leave that up to you :)
      Tim Kiebert
      Eagle Creek Citrus
      A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

      Comment


        #4
        Re: read and parse an xml file

        I have extensive experience in using the stringscanner functions, and you can get almost every XML job done with it.

        However, it does not give you the feeling of being a "native solution" to parse XML. You are just 'constructing' an 'alternative' solution that would work.

        I have some heavy XML operations ahead of me, and I will investigate the XML functions that are available in V9 now first.

        I think that XML handling is one of those things that hardly will be used by the average Alpha Five user, but almost in any case need to be used by the professional that builds for medium to larger companies. It would be great if Alpha would have more user friendly solutions to handle it.

        However, it would also mean a bridge between OO-structured programming and linear XBasic programming, which might turn out rather difficult to realize?

        Comment


          #5
          Re: read and parse an xml file

          Using this code:
          trace.clear()
          '"c:\alpha5v9\BSECalendar\text14\
          xml_data = ""
          xml_data2 = ""
          file.copy2("C:\Alpha5v9\BSECalendar\Calendarpro14\events.xml","c:\alpha5v9\BSECalendar\text14\zzparse.txt")
          xml_data = file.to_string("c:\alpha5v9\BSECalendar\text14\zzparse.txt")
          xml_data = stritran(xml_data,"</event><event>","</event><event>"+crlf())
          trace.WriteLn(xml_data)

          Gives these results in the trace window.
          How can I get rid of the <data><events><event> on the first line

          <data><events><event><event_id> 26</event_id><title>P-card Audit</title><date>02/01/2010</date><date_to>02/01/2010</date_to><time>08:30</time><time_to>04:30</time_to><category>Business</category><location>Lakin Hospital</location><recursive_freq>Does Not repeat</recursive_freq><description>P-card Audit</description><url>Needs to link to the Edit Events Form?Event_Id=26</url><image>Images/Pcard.jpg</image></event><event>

          <event_id> 27</event_id><title>P-Card Audit</title><date>02/08/2010</date><date_to>02/08/2010</date_to><time>08:30</time><time_to>04:30</time_to><category>Business</category><location>Diamond Building</location><recursive_freq>Repeats Weekly</recursive_freq><description>P-Card Audit</description><url>Needs to link to the Edit Events Form?Event_Id=27</url><image>Images/Pcard.jpg</image></event><event>

          <event_id> 28</event_id><title>P-Card-Elkins</title><date>02/22/2010</date><date_to>02/26/2010</date_to><time>08:30</time><time_to>04:30</time_to><category>Business</category><location>Elkins Children Home</location><recursive_freq>Does Not repeat</recursive_freq><description>P-Card-Elkins</description><url>Needs to link to the Edit Events Form?Event_Id=28</url><image>Images/Pcard.jpg</image></event><event>

          <event_id> 29</event_id><title>P-card-Welch</title><date>03/01/2010</date><date_to>03/02/2010</date_to><time>08:30</time><time_to>04:30</time_to><category>Business</category><location>Welch-BCF Social Services</location><recursive_freq>Does Not repeat</recursive_freq><description>P-card-Welch</description><url>Needs to link to the Edit Events Form?Event_Id=29</url><image>Images/Pcard.jpg</image></event><event>

          <event_id> 30</event_id><title>test 2nd Event</title><date>02/05/2010</date><date_to>02/05/2010</date_to><time>08:00</time><time_to>10:00</time_to><category>Business</category><location>WVDHHR</location><recursive_freq>Does Not repeat</recursive_freq><description>test 2nd Event</description><url>Needs to link to the Edit Events Form?Event_Id=30</url><image>Images/Pcard.jpg</image></event><event>

          <event_id> 31</event_id><title>test 1st Event</title><date>02/05/2010</date><date_to>02/05/2010</date_to><time>10:30</time><time_to>12:00</time_to><category>Business</category><location>WVDHHR</location><recursive_freq>Does Not repeat</recursive_freq><description>test 1st Event</description><url>Needs to link to the Edit Events Form?Event_Id=31</url><image>Images/Pcard.jpg</image></event></events

          Comment


            #6
            Re: read and parse an xml file

            Originally posted by crimmelcp View Post
            How can I get rid of the <data><events><event> on the first line
            Do you really need to get rid of it?
            In the code you provided in the first post you are using 'extract_string'. This will ignore any extra data that you don't need.
            Tim Kiebert
            Eagle Creek Citrus
            A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

            Comment


              #7
              Re: read and parse an xml file

              How can I get rid of the <data><events><event> on the first line
              ln = "<data><events><event><event_id> 26</event_id><title>P-card "

              newline = strtran(ln,"<data><events><event>","")
              ? newline
              = "<event_id> 26</event_id><title>P-card "
              xml_data = stritran(xml_data,"</event><event>","</event><event>"+crlf()) 'present line
              xml_data = strtran(xml_data,"<data><events><event>","",1,1) 'new line after that
              There can be only one.

              Comment


                #8
                Re: read and parse an xml file

                Stan:
                That works fine when I view in trace window.
                each Event_id is on a separate line

                But when I write to a table then all of the event_id's are on the same line again.
                Any ideas

                file.copy2("C:\Alpha5v9\BSECalendar\Calendarpro14\events.xml","c:\alpha5v9\BSECalendar\text14\zzparse.txt")
                xml_data = file.to_string("c:\alpha5v9\BSECalendar\text14\zzparse.txt")
                xml_data1 = stritran(xml_data,"</event><event>","</event><event>"+crlf()) 'present line
                xml_data1 = strtran(xml_data1,"<data><events><event>","",1,1) 'new line after that
                trace.WriteLn(xml_data1)

                t=table.open("zzxmlparse")
                t.enter_begin()
                t.Record1 = substr(xml_data1,1,150)
                t.Record2 = substr(xml_data1,151,151)
                t.Record3 = substr(xml_data1,302,150)
                t.enter_end()
                t.close()

                Comment


                  #9
                  Re: read and parse an xml file

                  Can you attach a sample of the original xml file? I'm not seeing what you're seeing.

                  Nevermind.

                  I think I know what you are saying now.

                  The whole of the text file is stores in a variable xml_data1. You are parsing out the 1-150th characters, the 151-302 characters, and the 302-452 characters. A crlf() is a character so that gets read just like any other.

                  Change your script to

                  Code:
                  file.copy2("C:\temp\events.xml","c:\temp\zzparse.txt")
                  xml_data = file.to_string("c:\temp\zzparse.txt")
                  xml_data1 = stritran(xml_data,"</event><event>","</event><event>"+crlf()) 'present line
                  xml_data1 = strtran(xml_data1,"<data><events><event>","",1,1) 'new line after that
                  trace.WriteLn(xml_data1)
                  
                  fst_line = word(xml_data1,1,crlf()) [COLOR="Red"]'get the first line (start to crlf())[/COLOR] and parse that
                  t=table.open("zzxmlparse")
                  t.enter_begin()
                  t.Record1 = substr(fst_line,1,150)
                  t.Record2 = substr(fst_line,151,151)
                  t.Record3 = substr(fst_line,302,150)
                  t.enter_end()
                  t.close()
                  Last edited by Stan Mathews; 02-24-2010, 05:18 PM.
                  There can be only one.

                  Comment

                  Working...
                  X