aspose file tools*
The moose likes JSF and the fly likes XML schema into jsf datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "XML schema into jsf datatable" Watch "XML schema into jsf datatable" New topic
Author

XML schema into jsf datatable

Amrita SeungJo
Greenhorn

Joined: Apr 09, 2014
Posts: 4
I have an xml schema.. I need to display it as JSF datatable can anybody help me..

This is my xml schema

XML FILE

<?xml version="1.0" encoding="UTF-8"?>

<shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Shiporder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>

<orderperson>Maxwell</orderperson>
<shipto>
<name>John Maxwell</name>
<address>400 street</address>
<city>MexicanCity</city>
<country>US</country>
</shipto>
<item>
<title>Empire</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>120.00</price>
</item>
<item>
<title>Surprise</title>
<quantity>1</quantity>
<price>50.00</price>
</item>
</shiporder>


XSD FILE



<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:simpleType name="stringtype">
<xs:restriction base="xs:string" />
</xs:simpleType>

<xs:simpleType name="inttype">
<xs:restriction base="xs:positiveInteger" />
</xs:simpleType>

<xs:simpleType name="dectype">
<xs:restriction base="xs:decimal" />
</xs:simpleType>

<xs:simpleType name="orderidtype">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{6}" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="shiptotype">
<xs:sequence>
<xs:element name="name" type="stringtype" />
<xs:element name="address" type="stringtype" />
<xs:element name="city" type="stringtype" />
<xs:element name="country" type="stringtype" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="itemtype">
<xs:sequence>
<xs:element name="title" type="stringtype" />
<xs:element name="note" type="stringtype" minOccurs="0" />
<xs:element name="quantity" type="inttype" />
<xs:element name="price" type="dectype" />
</xs:sequence>
</xs:complexType>

<xs:complexType name="shipordertype">
<xs:sequence>
<xs:element name="orderperson" type="stringtype" />
<xs:element name="shipto" type="shiptotype" />
<xs:element name="item" maxOccurs="unbounded" type="itemtype" />
</xs:sequence>
<xs:attribute name="orderid" type="orderidtype" use="required" />
</xs:complexType>

<xs:element name="shiporder" type="shipordertype" />

</xs:schema>


Please reply soon as i need to submit it today for my college project :( :(
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

Actually, your "XML Schema" is the XSD file. The file you're calling the XML schema is simply XML data. The schema is the data structure definition.

To represent this XML data in a datatable, you need to convert it into something that a JSF DataModel object can wrap - in other words, an ordered collection of row objects such as a List or array.

One popular way to do this with XML is to use the Apache Digester, which can read XML and emit an object tree based on the rules that you provided the Digester with.

There are lots of other ways of doing this as well, such as JAXB.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: XML schema into jsf datatable