Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-08-2009
Member
 
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
Reply With Quote
  #2  
Old 10-08-2009
Member
 
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.
Reply With Quote
  #3  
Old 10-08-2009
Member
 
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.
Reply With Quote
  #4  
Old 10-08-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "javafx xml parsing example"
Thread Thread Starter Forum Replies Last Post
JavaFX into jsp file Bottlenecked Software Development 10 01-09-2010 10:22 PM
JavaFX is the right choice? Bricklayer Software Development 6 26-07-2010 10:34 AM
Strings in JavaFX Messenger Software Development 3 16-07-2010 04:57 PM
Threads in JavaFX Rily Software Development 3 15-07-2010 04:02 PM
JavaFX for Web Bricklayer Windows Software 4 15-07-2010 01:21 PM


All times are GMT +5.5. The time now is 01:25 AM.