Announcement

Collapse
No announcement yet.

Some help needed with XML

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

  • Some help needed with XML

    Hi all,

    I can't really seem to find XML examples that teach me how to make what I want.
    This is the case:
    I have an XML file which needs to be loaded, the first entry should be showed and then there would be a previous and a next button. Also a more details button which reads more fields from the xml file. I also want to have some pictures in it (which have locations online).

    So for example let's say that this is my XML file:

    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <Objects>
    - <Object ObjectID="Entry1">
       <Name>Sample Name</Name> 
       <ShortDesc>This is a short description</ShortDesc>
       <LongDesc>This is the long description which needs to be shown only if the More Information button is pressed</LongDesc>
    - <Pictures>
       <picture1>http://www.somesite.some/someimage.jpg</picture1> 
       <picture2>http://www.somesite.some/anotherimage.jpg</picture2> 
       </Pictures>
    </Object>
    
    - <Object ObjectID="Entry2">
       <Name>Sample Name 2</Name> 
       <ShortDesc>This is a short description for entry 2</ShortDesc>
       <LongDesc>This is the long description which needs to be shown only if the More Information button is pressed for entry 2</LongDesc>
    - <Pictures>
       <picture1>http://www.somesite.some/imageagain.jpg</picture1> 
       <picture2>http://www.somesite.some/anotherimageagain.jpg</picture2> 
       </Pictures>
    </Object>
    </Objects>
    I hope you see the thing I like. I'd like to read out certain fields and display them in a paragraph or label in AMS. Then on the More Information field I'd like to read out other fields.
    If possible I'd even like to have a slideshow with all pictures, or just show the first image and have a next button for the next image.

    Could anybody help me out or guide me into reading out XML. I didn't find this in the help, just some examples I can't get wise of.

    Thanks.

  • #2
    What you want to do should be fairly easy to attain. Here is what I would recommend you do to try to build the project.

    Load the XML file.
    If the load is successful then I would count the number of Objects\Object elements that are contained in the file. This number will be used to access the next field and the current field.
    Access the first object using the Objects\Object:1 syntax and extract the data from that entry that you want. I would recommend that the number of the object you are currently viewing be defined as a global variable and not a local.
    On your Next button I would take the global object variable and increase it by one, and verify that that number is not larger than the total number of Object elements in the XML file. (if it is larger then set it back to 1 to wrap back to the first Object). Then use that to load the next Objects\Object:2 element.
    On the Back button again take the global object variable and decrease it by one and verify that it is not less than one. If it is then set it to the Max number of object elements to load the last one in the list and then load that onto your page.
    And finally for the more info button I would use the global variable you have defined to extract the data from your XML and then display that on your page in the format you want to use. Load any images as necessary.

    HTH
    Give the above approach a try, the help file is good about describing how to use the XML components. If you get stuck export your project and load it here and we can help with the coding.
    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

    Comment


    • #3
      I'm stuck at the moment.
      I have this in the On Startup:

      Code:
      XML.Load("AutoPlay\\Docs\\demo.xml");
      The start of the file is like this:

      Code:
      <?xml version="1.0" encoding="UTF-8" ?> 
      <Objecten>
      
      <Object ObjectID="Demo01" KlantID="54321">
      	<Straatnaam>Teststraat</Straatnaam>
      	<Huisnummer>12345</Huisnummer>
      	<Postcode>1234 AA</Postcode>
      	<Woonplaats>Teststad</Woonplaats>
      	<Land>NL</Land>
      and so on. So I made a button which should give me the output of let's say <Straatnaam>, so this is the code in On Click:

      Code:
      attribute_result = XML.GetAttribute("Object", "Straatnaam");
      error = Application.GetLastError();
      if (error == 0) then
           Dialog.Message("Attribute Value", "The result is: "..attribute_result);
      else
           Dialog.Message("Error", _tblErrorMessages[error]);
      end
      When I press that button it gives no output but a dialog that says The result is:
      So there is no result, what can be wrong?

      Comment


      • #4
        I've got the above fixed, it needed to be XML.GetValue and not XML.GetAttribute.

        Next thing I run in to is not being able to get online pictures. Here's an example:

        Code:
        xfoto = XML.GetValue("Objecten/Object/Fotos/foto1:1");
        Label.SetText("Label2", xfoto);
        Image.Load("Image1", xfoto);
        Image.SetVisible("Image1", true);
        The label gives the correct URL, but Image.Load doesn't. When I put a local image there it does work. Isn't this possible?

        Comment


        • #5
          Here is a quick example showing the navigation buttons and the more info component. It is very simplistic and I didn't add much for error checking. Hope this helps.
          Attached Files
          TJ-Tigger
          "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
          "Draco dormiens nunquam titillandus."
          Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

          Comment


          • #6
            Thanks!
            It works great, so I'll look at what you did and try to make it work.
            But do you know if my last question is true? Can I just do an Image.Load to an URL?
            I have to make some kind of thing that downloads the XML file once a day, so maybe I need to do the pictures as well, but I'll know this only when I get the real XML file (I just have a sample with a bunch of stuff in it, but no actual images).

            Comment


            • #7
              No you cannot load an image from a URL. You will have to have the picture local on the system where AMS is running or load the URL into a web object instead.
              TJ-Tigger
              "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
              "Draco dormiens nunquam titillandus."
              Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

              Comment


              • #8
                just a question his XML file is includes a header AMS does not need this does it?
                all the demos in the past i seen never use the XML header i only ever see that in web projects these days am i wrong ?

                Comment


                • #9
                  good question Rex. I tested it with the above app and XML file it works with or without the file. I often put it in for compatibility with other apps.
                  TJ-Tigger
                  "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                  "Draco dormiens nunquam titillandus."
                  Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                  Comment


                  • #10
                    Originally posted by TJ_Tigger View Post
                    good question Rex. I tested it with the above app and XML file it works with or without the file. I often put it in for compatibility with other apps.
                    Intresting thanks for the details I not really seen and change in XML for a every long time so maybe its not really needed

                    Comment


                    • #11
                      Ok, it works now, most of it.

                      What I've done is: at the start (on startup) download the latest XML file online and save it to docs.

                      Code:
                      HTTP.Download("http://location.to/xmlfile.xml", "AutoPlay\\Docs\\feed.xml", MODE_BINARY, 20, 80, nil, nil, nil);
                      I want to have the images loaded too, I've done this in a web object, which is not ideal but for as far as I know the only way to show images directly from the internet:

                      Code:
                      plaatje = XML.GetValue("Objecten/Object:"..nObj.."/fotos/foto:1");
                      Web.LoadURL("Web1", plaatje);
                      It works, but I kind of miss the option to remove the scrollbars and the border shadow thing. Is this removable?
                      Or is there any other way to get the images displayed (maybe by downloading them, but the problem is the <foto> tag in the XML file shows the full URL, not just the image name).

                      Comment


                      • #12
                        Fixed the above (well, the borders) by using the IExplorer plugin. Now I'm just stuck with the scrollbars, for the rest it works.

                        Comment


                        • #13
                          There is the HTTP.Download action where you could download the image to a tmp directory and then once that is finished load that into an image object.
                          TJ-Tigger
                          "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                          "Draco dormiens nunquam titillandus."
                          Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                          Comment


                          • #14
                            Hm I think this will take too long and also stuff gets cluttered up too much, because there are about 800 images in this application which it just shows online. Also you'd see the download image display all the time.
                            But maybe the scrollbars aren't that big of a problem, it depends on what the end user wants.

                            Comment


                            • #15
                              FYI:

                              just a question his XML file is includes a header AMS does not need this does it?
                              Note: According to the XML specification, the XML declaration can only be omitted if the document is encoded in UTF-8 or UTF-16 or if the encoding information is provided externally through a transfer protocol for example. Even then, it is advised to keep the declaration in the document.
                              AMS SHOULD be using the declaration, or at least provide a argument to XML.Save to omit the declaration, i think IR proberly dropped the XML declaration for use of other xml bases file formats (smil or wpl for instance)

                              Comment

                              Working...
                              X