Hi,
I try to get output xml from input xsd, input xml, output xsd using SAX API.
here input xml like this :
It is not complete...because of space and avoid verbose
<?xml version="1.0" encoding="ISO-8859-1"?>
<movielink xsi:schemaLocation="http://www.movielink.com/adf movielink_adf.xsd" xmlns="http://www.movielink.com/adf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<productCatalog>
<category id="cat10002">
<name>Comedy</name>
<childProduct id="prod30073"/>
<childProduct id="prod130076"/>
</category>
<category id="cat10004">
<name>Drama</name>
<childProduct id="prod40018"/>
<childProduct id="prod110052"/>
</category>
<category id="cat10009">
<name>Classics</name>
<childProduct id="prod30073"/>
<childProduct id="prod130076"/>
</category>
<category id="cat110014">
<name>Sci-Fi</name>
<childProduct id="prod30113"/>
<childProduct id="prod110064"/>
<childProduct id="prod200008"/>
<childProduct id="prod230033"/>
<childProduct id="prod210032"/>
</category>
<category id="cat130014">
<name>Short's Films</name>
<childProduct id="prod310041"/>
</category>
<category id="cat140019">
<name>Horror</name>
<childProduct id="prod360004"/>
<childProduct id="prod30002"/>
<childProduct id="prod370027"/>
</category>
<category id="cat140021">
<name>Independent</name>
<childProduct id="prod50010"/>
<childProduct id="prod310041"/>
</category>
<category id="cat40014">
<name>Action</name>
<childProduct id="prod40018"/>
<childProduct id="prod110050"/>
<childProduct id="prod30113"/>
<childProduct id="prod150026"/>
<childProduct id="prod210030"/>
<childProduct id="prod200008"/>
<childProduct id="prod230046"/>
<childProduct id="prod210066"/>
<childProduct id="prod160027"/>
<childProduct id="prod230033"/>
<childProduct id="prod300036"/>
<childProduct id="prod310016"/>
<childProduct id="prod290108"/>
<childProduct id="spider_man_low_prd"/>
<childProduct id="spider_man_high_prd"/>
</category>
<category id="cat70013">
<name>Thriller</name>
<childProduct id="prod370027"/>
<childProduct id="prod370040"/>
</category>
<category id="cat70015">
<name>Family</name>
<childProduct id="prod90014"/>
<childProduct id="prod120004"/>
</category>
<category id="natgeo_sample_cat1">
<name>National Geographic Sample Content</name>
<childProduct id="natgeo_sample_prd1"/>
<childProduct id="natgeo_sample_prd2"/>
<childProduct id="natgeo_sample_prd3"/>
<childProduct id="natgeo_sample_prd4"/>
</category>
<category id="cat_slot5">
<name>New Releases</name>
<childProduct id="prod170019"/>
<childProduct id="prod170017"/>
<childProduct id="prod280031"/>
</category>
<category id="cat_slot3">
<name>Top Downloads</name>
<childProduct id="prod170019"/>
</category>
<product id="prod30073">
<name>Any Wednesday - another really long title to
test whether CSR actually truncates long titles</name>
<sortName>Any Wednesday</sortName>
<releaseYear>2003</releaseYear>
<shortDescription>An agent from the DEA is brought in to investigate the disappearances of Army Ranger cadets and their instructor during an exercise at a basic training camp in Louisiana.</shortDescription>
<longDescription>Academy Award� nominees John Travolta (Best Actor in a Leading Role, "Pulp Fiction," 1994.) and Samuel L. Jackson (Best Actor in a Supporting Role, "Pulp Fiction," 1994.) team up with action director John McTiernan ("Die Hard," "The Hunt for Red October," "Predator") in a white-knuckle "thrill ride with a twist you won't believe!" (MairiAnna Bachynsky, ATV/CTV ENTERTAINMENT). Also starring Connie Nielsen ("The Hunted," "Gladiator"), Giovanni Ribisi ("Gone in Sixty Seconds"), Brian Van Holt ("Black Hawk Down"), Taye Diggs ("Chicago") and Roselyn Sanchez ("Rush Hour 2"). A DEA officer (Travolta) is recruited to investigate the mysterious disappearance of a famed U.S. Army drill instructor (Jackson) and a group of cadets on a routine military exercise in the jungles of Panama. But the journey to uncover the truth leads to some dangerous and unexpected places when two rescued survivors tell dramatically different versions of what transpired. "Totally mesmerizing." (Lisa Petrillo, WFOR/CBS (Miami)/EXTRA).</longDescription>
<productURI>
http://engine-dev.digitaldist.net/commerce/detail/ProductDetail.jhtml?id=prod30073</productURI>
<relatedProduct id="prod170017"/>
<relatedProduct id="prod110058"/>
<runTime>99</runTime>
<copyright>� 1966 Warner Bros. All Rights Reserved.</copyright>
<mpaaRating>
<rating>R</rating>
<explanation>Rated R for violence and language</explanation>
</mpaaRating>
<credit>
<type>Cast</type>
<text>Dean Jones</text>
</credit>
<credit>
<type>Cast</type>
<text>Taye Diggs</text>
</credit>
<credit>
<type>Cast</type>
<text>Samuel L. Jackson</text>
</credit>
<credit>
<type>Directed By</type>
<text>John McTiernan</text>
</credit>
<credit>
<type>Written By</type>
<text>Muriel Resnik (Story), Julius J. Epstein (Screenplay)</text>
</credit>
<boxart>
<file>
<usage>Thumbnail</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m770234//Basic_2003/Basic_boxart_small.jpg</uri>
<size>3539</size>
</file>
<file>
<usage>Small</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m770232/Basic_boxart_med.gif</uri>
<size>8350</size>
</file>
<file>
<usage>Large</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m770230/Basic_boxart_large.jpg</uri>
<size>12039</size>
</file>
</boxart>
<still>
<file>
<usage>Thumbnail</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m30041/AnyWednesday_still3_small.gif</uri>
<size>2583</size>
</file>
<file>
<usage>Large</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m30042/AnyWednesday_still3.jpg</uri>
<size>29488</size>
</file>
</still>
<still>
<file>
<usage>Thumbnail</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m30037/AnyWednesday_still1_small.gif</uri>
<size>2496</size>
</file>
<file>
<usage>Large</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m30038/AnyWednesday_still1.jpg</uri>
<size>27654</size>
</file>
</still>
<still>
<file>
<usage>Thumbnail</usage>
<uri>
http://images.movielink.com/MEDIA/CustomProductCatalog/m30039/AnyWednesday_still2_small.gif</uri>
<size>2586</size>
</file>
Input schema :
<!-- -->
<xs:element name="movielink">
<xs:complexType>
<xs:sequence>
<xs:element name="productCatalog" type="ml
roductCatalog">
<xs:key name="productID_PrimaryKey">
<xs:selector xpath="ml
roduct"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:key name="categoryID_PrimaryKey">
<xs:selector xpath="ml:category"/>
<xs:field xpath="@id"/>
</xs:key>
<xs:unique name="categoryName_UniquePerCatalog">
<xs:selector xpath="ml:category"/>
<xs:field xpath="ml:name"/>
</xs:unique>
</xs:element>
<xs:element name="error" type="ml:errorType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- -->
<!-- Product Catalog -->
<!-- -->
<xs:complexType name="productCatalog">
<xs:sequence>
<xs:element name="category" type="ml:categoryType" maxOccurs="unbounded">
<xs:unique name="productID_UniquePerCategory">
<xs:selector xpath="ml:childProduct"/>
<xs:field xpath="@id"/>
</xs:unique>
<xs:unique name="categorytID_UniquePerCategory">
<xs:selector xpath="ml:category"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
<xs:element name="product" type="ml
roductType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Output schema :
?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://services.twowire.com/vc" xmlns:vc="http://services.twowire.com/vc" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0" xml:lang="en">
<xs:annotation>
<xs
ocumentation>2Wire Downloadable Video Catalog Schema</xs
ocumentation>
<xs
ocumentation>Confidential Property of 2Wire, Inc.</xs
ocumentation>
<xs
ocumentation>(c) 2004 2Wire, Inc.</xs
ocumentation>
</xs:annotation>
<xs:include schemaLocation="dvc_base_types.xsd"/>
<xs:element name="videoCatalogList">
<xs:complexType>
<xs:sequence>
<xs:element name="catalogUpdateDate" type="xs
ateTime" minOccurs="0"/>
<xs:element name="dataSource" type="vc
artner" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="topDownloads" type="vc:topList" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="videoCatalog">
<xs:complexType>
<xs:sequence>
<xs:element name="video" type="vc:video" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="topDownloadsList">
<xs:complexType>
<xs:sequence>
<xs:element name="videoInfo" type="vc:videoInfo" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This is
java file give output xml...
public class JAXBTest
{
static
String name=null,id=null,Tier=null,rating=null,explanation=null,language=null,actor="",director="", writer="",screenformat=null,quality=null,copyright=null,text="",type="",synopsis=null;
static BigDecimal price = new BigDecimal(0.0);
static BigInteger releaseyear = new BigInteger("0");
static BigInteger runtime = new BigInteger("0");
static Calendar startDate=null, endDate=null;
static boolean newRelease=false;
static List videolist;
static movielink.Image img;
static movielink.Stream stream;
public static void main(String args[])
{
try{
//We need to unmarshall the xml to a java object
JAXBContext jc = JAXBContext.newInstance("movielink");
Unmarshaller u = jc.createUnmarshaller();
// Type cast it to the PurchaseOrder Object
Movielink ml = (Movielink)u.unmarshal( new java.io.File( "complete.xml" ) );
jc = JAXBContext.newInstance( "dvc" );
Marshaller m = jc.createMarshaller();
//Create the output Object
dvc.ObjectFactory objFactory=new dvc.ObjectFactory();
//Get the Product Catalog
movielink.ProductCatalog pc = ml.getProductCatalog();
OutputStream os = new FileOutputStream( "dvc.xml" );
dvc.VideoCatalogList videocataloglist=objFactory.createVideoCatalogList();
dvc.VideoCatalogListType videoCatalogListType=objFactory.createVideoCatalogListType();
dvc.VideoCatalogListType.VideoCatalogType vctype=objFactory.createVideoCatalogListTypeVideoCatalogType();
videocataloglist.setCatalogUpdateDate(Calendar.getInstance());
List listProduct = pc.getProduct();
for(int i=0;i<listProduct.size();i++)
{
ProductType pt=(ProductType) listProduct.get(i);
name=pt.getName();
id=pt.getId();
releaseyear=pt.getReleaseYear();
runtime=pt.getRunTime();
img =pt.getBoxart();
stream=pt.getTrailer();
synopsis=pt.getLongDescription();
movielink.ProductType.MpaaRatingType mpaarating=pt.getMpaaRating();
rating=mpaarating.getRating();
explanation=mpaarating.getExplanation();
/* get credit */
List creditlist=pt.getCredit();
List skulist=pt.getSku();
videolist =vctype.getVideo();
System.out.println("nimish size"+videolist.size());
videolist.add(createOutputlist(objFactory,skulist,creditlist)) ;
}
List datasourcelist = videocataloglist.getDataSource();
dvc.Partner partner=objFactory.createPartner();
partner.setId("ML");
partner.setName("Movielink");
datasourcelist.add(partner);
List topdownloadlist=videocataloglist.getTopDownloads();
dvc.TopList toplist=objFactory.createTopList();
toplist.setPartnerId("ML");
List videokeylist=toplist.getVideoKey();
videokeylist.add("ollo");
videocataloglist.setVideoCatalog(vctype);
List listCategory = pc.getCategory();
for(int cat_cnt=0; cat_cnt<listCategory.size();cat_cnt++)
{
CategoryType cattype= (CategoryType)listCategory.get(cat_cnt);
}
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
//for schema location
m.setProperty( Marshaller.JAXB_SCHEMA_LOCATION, "http://www.w3schools.com output.xsd" );
//marshall it to the output.xml file
m.marshal(videocataloglist,os);
}
catch(Exception e){
e.printStackTrace();
}
}
public static dvc.Video createOutputlist(dvc.ObjectFactory objFactory,List skulist,List creditlist) throws Exception
{
dvc.Video.CreditType crtype=objFactory.createVideoCreditType();
dvc.VideoCatalogListType.VideoCatalogType vctype=objFactory.createVideoCatalogListTypeVideoCatalogType();
List videolist =vctype.getVideo();
List sku ,credit1;
dvc.Video video=objFactory.createVideo();
try
{
sku=video.getSku();
sku=createaddSku(objFactory,skulist,video);
video.setProviderId("ML");
video.setProductId(id);
video.setId(id);
video.setTitle(name);
video.setSynopsis(synopsis);
dvc.Video.AvailabilityType Atype=objFactory.createVideoAvailabilityType();
Atype.setStartDate(startDate);
Atype.setEndDate(endDate);
Atype.setNewRelease(newRelease);
video.setAvailability(Atype);
//video.setDirector(director);
video.setMpaaRating(rating);
video.setPrice(price);
video.setRunTime(runtime);
video.setProducer("n.a");
video.setLongDescription(explanation);
video.setDownloadWindow(null);
dvc.LinkURLType linkurltype=video.getBoxart();
video.setBoxart(linkurltype);
linkurltype=video.getTrailer();
video.setTrailer(linkurltype);
video.setRentalUri("n.a");
video.setStarring("AMITABH");
video.setViewingWindow(new BigInteger("10"));
dvc.AnyType anyType = objFactory.createAnyType();
List lAnyType = anyType.getContent();
lAnyType.add("sss");
video.setSubtitles(anyType);
// credit1 = video.getCredit();
credit1=createaddcredit12(objFactory,creditlist,video);
}
catch(Exception e)
{
e.printStackTrace();
throw new Exception(e);
}
for(int i=0; i<credit1.size();i++)
{
crtype=(dvc.Video.CreditType)credit1.get(i);
}
return video;
}
public static List createaddSku(dvc.ObjectFactory objFactory,List skulist,dvc.Video video)throws Exception
{
dvc.Video.SkuType sktype=objFactory.createVideoSkuType();
List sku ;
sku=video.getSku();
for(int s_cnt=0; s_cnt<1;s_cnt++)
{
movielink.SkuType skutype=(movielink.SkuType)skulist.get(s_cnt);
List Pricelist =skutype.getPrice();
language=skutype.getLanguage();
screenformat=skutype.getScreenFormat();
quality=skutype.getQuality();
for(int pr_cnt=0; pr_cnt<Pricelist.size();pr_cnt++)
{
SkuType.PriceType pType=(SkuType.PriceType)Pricelist.get(pr_cnt);
price=pType.getPriceAmount();
}
List formatlist=skutype.getFormat();
for(int fcnt=0;fcnt<formatlist.size();fcnt++ ) {
SkuType.FormatType ftype= ( SkuType.FormatType)formatlist.get(fcnt);
String fileformat =ftype.getFileFormat();
movielink.SkuType.AvailabilityType AvailType=skutype.getAvailability();
newRelease=AvailType.isNewRelease();
startDate=AvailType.getStartDate();
endDate=AvailType.getEndDate();
if(newRelease)
{
Tier="1st Release ";
}
else Tier="Library";
sktype.setId(id);
sktype.setPrice(price);
sktype.setFormat(screenformat);
sktype.setOffering("n.a");
sktype.setQuality(quality);
sktype.setRerent("n.a");
sku.add(sktype);
}
}
return sku ;
}
// addde here
public static List createaddcredit12(dvc.ObjectFactory objFactory,List creditlist,dvc.Video video )throws Exception
{
dvc.Video.CreditType crtype=null;
String text=null,type=null;
List credits = video.getCredit();
System.out.println("the size of the input list .."+creditlist.size());
for(int c_cnt=0; c_cnt<creditlist.size();c_cnt++)
{
dvc.Video.CreditType credittype=objFactory.createVideoCreditType();
movielink.ProductType.CreditType credittypeml=(movielink.ProductType.CreditType)creditlist.get(c_cnt);
type= credittypeml.getType().trim();
text=credittypeml.getText();
System.out.println(c_cnt+"yyy"+type+"xx"+text);
credittype.setText(text);
credittype.setType(type);
credits.add(c_cnt, credittype);
}
System.out.println("the size is.."+credits.size());
for(int i=0; i<credits.size();i++)
{
dvc.Video.CreditType crtype1=(dvc.Video.CreditType)credits.get(i);
}
return credits;
}
}
---------------------------------------------------------
i get output like....
?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<videoCatalogList xsi:schemaLocation="http://www.w3schools.com output.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://services.twowire.com/vc">
<catalogUpdateDate>2005-08-19T12:30:04.158+05:30</catalogUpdateDate>
<dataSource ns1:id="ML" xmlns:ns1="http://services.twowire.com/vc">
<name>Movielink</name>
</dataSource>
<videoCatalog>
<video ns2:id="prod30073" xmlns:ns2="http://services.twowire.com/vc">
<providerId>ML</providerId>
<productId>prod30073</productId>
<title>Any Wednesday - another really long title to test whether CSR actually truncates long titles</title>
<synopsis>Academy Award� nominees John Travolta (Best Actor in a Leading Role, "Pulp Fiction," 1994.) and Samuel L. Jackson (Best Actor in a Supporting Role, "Pulp Fiction," 1994.) team up with action director John McTiernan ("Die Hard," "The Hunt for Red October," "Predator") in a white-knuckle "thrill ride with a twist you won't believe!" (MairiAnna Bachynsky, ATV/CTV ENTERTAINMENT). Also starring Connie Nielsen ("The Hunted," "Gladiator"), Giovanni Ribisi ("Gone in Sixty Seconds"), Brian Van Holt ("Black Hawk Down"), Taye Diggs ("Chicago") and Roselyn Sanchez ("Rush Hour 2"). A DEA officer (Travolta) is recruited to investigate the mysterious disappearance of a famed U.S. Army drill instructor (Jackson) and a group of cadets on a routine military exercise in the jungles of Panama. But the journey to uncover the truth leads to some dangerous and unexpected places when two rescued survivors tell dramatically different versions of what transpired. "Totally mesmerizing." (Lisa Petrillo, WFOR/CBS (Miami)/EXTRA).</synopsis>
<longDescription>Rated R for violence and language</longDescription>
<price>2.95</price>
<availability>
<startDate>2002-09-01</startDate>
<endDate>2005-10-30</endDate>
<newRelease>false</newRelease>
</availability>
<rentalUri>n.a</rentalUri>
<runTime>99</runTime>
<mpaaRating>R</mpaaRating>
<starring>AMITABH</starring>
<producer>n.a</producer>
<credit>
<type>Cast</type>
<text>Dean Jones</text>
</credit>
<credit>
<type>Cast</type>
<text>Taye Diggs</text>
</credit>
<credit>
<type>Cast</type>
<text>Samuel L. Jackson</text>
</credit>
<credit>
<type>Directed By</type>
<text>John McTiernan</text>
</credit>
<credit>
<type>Written By</type>
<text>Muriel Resnik (Story), Julius J. Epstein (Screenplay)</text>
</credit>
<sku id="prod30073">
<format>Standard</format>
<offering>n.a</offering>
<rerent>n.a</rerent>
<price>2.95</price>
<quality>STANDARD</quality>
</sku>
it is not complete,but it is working...
MY problem is that i want "vc: " against xml node...
<vc:sku> ,<vc:credit >
so how can i do this ?
please help me.
Thanks in anticipation..
rgds,
Nimish
This is java file give output xml...