Results 1 to 4 of 4

Thread: javafx xml parsing example

  1. #1
    Join Date
    May 2008
    Posts
    20

    javafx xml parsing example

    Hi,

    I need javafx xml parsing example. Actually I am a bit confused & not getting what i exactly want to achieve with my code. Can someone please provide an working example or say a tutorial on this topic?.

    Thanks in advance.
    russ_da_buss

  2. #2
    Join Date
    May 2008
    Posts
    34

    Re: javafx xml parsing example

    Xml Parsing Example

    JavaFX

    XML Animal Search based on a Top Category and Sub Category criteria.

    Notice the application looks and seemingly functions exactly like the Binding example, but in this case the data is obtained from two Xml documents upon start of application. This application Search's a group of Animals through the user selecting a pre-defined top category and/or sub category. Filtering occurs upon Search. This example highlights JavaFx's XML parsing ability, Binding and Trigger capabilities, use of Object Models and creating a relationship between Objects.

    ON STARTUP:
    Upon startup, Category, Sub Category and Animal arrays are populated with relevant ID references from Xml Documents. DropDowns are created, and populated using category data. The stage is created, and each content component is created and inserted onto the stage.

    KEY FEATURES:
    1. Xml Parsing capabilities.
    2. Binding components to variables, and to the stage.
    3. Uses several Object models, with an array relationship.
    4. Uses the Trigger 'on replace' method on a binded object.
    5. Uses Swing Components.

    APPLICATION NOTES:
    * Data is obtained from two locally packaged Xml Documents
    * Uses 2 object models - Category, and Animal.
    * Contains 2 Top Categories, and 6 Sub Categories.
    * Total Animals include 30.


    Embedding Script in page.

    Simply embed the following code in any html page with Java installed and internet access and the project should run.

    Code:
    <script src="http://dl.javafx.com/1.1/dtfx.js"></script><script>
        javafx({
                  archive: "http://www.gieman.com/applets/xmlParser.jar",
                  width: 260,
                  height: 620,
                  code: "xmlparser.Main",
                  name: "xmlParser"
            });</script>
    I hope this example will help you.

  3. #3
    Join Date
    May 2008
    Posts
    22

    Re: javafx xml parsing example

    JavaFX HTTP Networking and XML Parsing

    JavaFX HTTP and XML Package Overview

    To develop an application using HTTP protocol and XML, JavaFX provides several packages, which are shown below:

    * javafx.io.http for handling HTTP communication
    * javafx.data.pull and javafx.data.xml for XML parsing


    HTTP and JavaFX

    XML API

    Integrating the HTTP and XML APIs

    This one is another example that will help you understand the whole process in details.

  4. #4
    Join Date
    May 2008
    Posts
    41

    Re: javafx xml parsing example

    Getting Weather Forecast from Yahoo!

    This example shows how to parse XML in the JavaFX programming language

    Information about weather forecasts is obtained by performing an HTTP GET request by using the JavaFX asynchronous HTTP API, as shown in Figure 1. Note that the input stream should be closed even if an error occurs.

    Code:
    HttpRequest {
            location: url
            onDone: function() {
              // check for errors after parsing
              if (forecast.isEmpty()) 
                location = "Loading error"
            }
            onInput: function(input) {
              try {
                // parse input stream
                // see Figure 2
              } finally {
                input.close()
              }
            }
          }.enqueue()
    The response document is parsed by using the JavaFX XML pull parser to extract information about the location and the forecast for that location.

    Code:
    PullParser {
                  var wind: Wind;
                  var temp: String;
                  var speed: String;
                  input: input
                  onEvent: function(event) {
                    if ((event.type == PullParser.START_ELEMENT) and (event.qname.prefix == "yweather")) {
                      if (event.qname.name == "location") {
                        location = event.getAttributeValue(QName{name:"city"});
                        def region = event.getAttributeValue(QName{name:"region"});
                        if (0 < region.length()) {
                          location = "{location}, {region}"
                        }
                      }
                      else if (event.qname.name == "units") {
                        temp  = event.getAttributeValue(QName{name:"temperature"});
                        speed = event.getAttributeValue(QName{name:"speed"})
                      }
                      else if (event.qname.name == "wind") {
                        wind = Wind {
                          angle: event.getAttributeValue(QName{name:"direction"})
                          speed: event.getAttributeValue(QName{name:"speed"})
                          unit:  speed
                        }
                      }
                      else if (event.qname.name == "condition") {
                        insert Forecast {
                          day: "Now"
                          high: event.getAttributeValue(QName{name:"temp"})
                          text: event.getAttributeValue(QName{name:"text"})
                          code: event.getAttributeValue(QName{name:"code"})
                          unit: temp
                          wind: wind
                        } into forecast
                      }
                      else if (event.qname.name == "forecast") {
                        insert Forecast {
                          day:  event.getAttributeValue(QName{name:"day"})
                          low:  event.getAttributeValue(QName{name:"low"})
                          high: event.getAttributeValue(QName{name:"high"})
                          text: event.getAttributeValue(QName{name:"text"})
                          code: event.getAttributeValue(QName{name:"code"})
                          unit: temp
                        } into forecast
                      }
                    }
                  }
                }.parse()
    Customizing the Code

    The Config class contains the following variables that affect the appearance of the weather widget.

    WIDTH
    Preferred width of the widget, but actual width depends on scene width
    HEIGHT
    Height of the widget
    SPACE
    Default spacing between components
    SMALL_FONT
    Font used for small text: forecast name, temperature, and wind speed
    LARGE_FONT
    Font used for large text: location and short description
    (it is calculated automatically)
    ROUND
    Diameter of the arc at the four corners of the rectangles
    FONT_COLOR
    Foreground color used for all text
    DARK_COLOR
    Main background color
    LIGHT_COLOR
    Lighter background color for creating the gradient filling

    Code:
    public def WIDTH = 320;
    public def HEIGHT = 170;
    
    public def SPACE = 2;
    public def SPACE_DOUBLE = 2 * SPACE;
    
    public def SMALL_FONT = Font {
      size: 12
    }
    public def LARGE_FONT = Font {
      size: SPACE + 2 * SMALL_FONT.size
    }
    
    public def ROUND = SMALL_FONT.size;
    public def OFFSET = HEIGHT - 6 * SPACE - 2 * LARGE_FONT.size;
    
    public def FONT_COLOR  = Color.WHITE;
    public def DARK_COLOR  = Color.DARKBLUE;
    public def LIGHT_COLOR = Color.LIGHTBLUE;
    Hope this example helps.

Similar Threads

  1. JavaFX into jsp file
    By Bottlenecked in forum Software Development
    Replies: 10
    Last Post: 01-09-2010, 10:22 PM
  2. JavaFX is the right choice?
    By Bricklayer in forum Software Development
    Replies: 6
    Last Post: 26-07-2010, 10:34 AM
  3. Strings in JavaFX
    By Messenger in forum Software Development
    Replies: 3
    Last Post: 16-07-2010, 04:57 PM
  4. Threads in JavaFX
    By Rily in forum Software Development
    Replies: 3
    Last Post: 15-07-2010, 04:02 PM
  5. JavaFX for Web
    By Bricklayer in forum Windows Software
    Replies: 4
    Last Post: 15-07-2010, 01:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,131,586.65766 seconds with 16 queries