Site Navigation:

sbxb

A simple binding example

This sample's code is located in the package {@link org.otvl.sbxbsamp.simple}.

The SoftBean object model

The sample's object model is provided here:

The target XML format

<House address="Autivielle">

<Door>red</Door>

<Room id="1">

<location>south</location>

living

<Window id="0">left</Window>

<Window id="1">right</Window>

<Door>green</Door>

<Door>white</Door>

</Room>

<Room id="2">

<location>south-east</location>

nice

<Window id="0">center</Window>

<Door>yellow</Door>

</Room>

</House>

The binding specification

hbs.org.otvl.sbxbsamp.simple.House.0.address=@address

hbs.org.otvl.sbxbsamp.simple.House.1.theDoor=Door(hbs)

hbs.org.otvl.sbxbsamp.simple.House.2.rooms=Room(hbs)

hbs.org.otvl.sbxbsamp.simple.Room.0.id=@id

hbs.org.otvl.sbxbsamp.simple.Room.1.location=location

hbs.org.otvl.sbxbsamp.simple.Room.2.name=.

hbs.org.otvl.sbxbsamp.simple.Room.3.windoz=Window(hbs)

hbs.org.otvl.sbxbsamp.simple.Room.4.theDoors=Door(hbs)

hbs.org.otvl.sbxbsamp.simple.Door.0.color=.

hbs.org.otvl.sbxbsamp.simple.Window.0.id=@id

hbs.org.otvl.sbxbsamp.simple.Window.1.location=.

Basic rules for writing a binding specification

The binding specification is a collection of numbered rules. A rule applies to a binding name (here "hbs") and a class to be bound.

Each rule has the following syntax:

bindingName.qualifiedClassName.index.sBeanProperty=XmlPath[(bindingName)]

The XML-path can be specified as following:

  • @attribute: an XML attribute of the current element

  • element: the name of a sub-element

  • .(dot): the text content of the current element, when using the API the empty string "" must be used instead of . (dot).

If a binding name follows the XmlPath, then a sub-object has to be handled with the corresponding binding specification. If not, then the property is a simple property on the current object.