Thursday 15 May 2014

java - Parse XSD and get a sample XML representantion -



java - Parse XSD and get a sample XML representantion -

i'm working parse wadl , write xml of wadl (with specifications), when response have representation of element 'tns:type', need parse included file xsd , sample representation , insert xml i'm creating. example:

xsd file included in wadl example

<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" targetnamespace="urn:yahoo:yn" xmlns="urn:yahoo:yn" elementformdefault="qualified"> <xs:element name="resultset"> <xs:complextype> <xs:sequence> <xs:element name="result" type="resulttype" minoccurs="0" maxoccurs="50"/> </xs:sequence> <xs:attribute name="totalresultsavailable" type="xs:integer"/> <xs:attribute name="totalresultsreturned" type="xs:integer"/> <xs:attribute name="firstresultposition" type="xs:integer"/> </xs:complextype> </xs:element> <xs:complextype name="resulttype"> <xs:sequence> <xs:element name="title" type="xs:string"/> <xs:element name="summary" type="xs:string"/> <xs:element name="url" type="xs:string"/> <xs:element name="clickurl" type="xs:string"/> <xs:element name="newssource" type="xs:string"/> <xs:element name="newssourceurl" type="xs:string"/> <xs:element name="language" type="xs:string"/> <xs:element name="publishdate" type="xs:string"/> <xs:element name="modificationdate" type="xs:string" minoccurs="0"/> <xs:element name="thumbnail" type="imagetype" minoccurs="0"/> </xs:sequence> </xs:complextype> <xs:complextype name="imagetype"> <xs:sequence> <xs:element name="url" type="xs:string"/> <xs:element name="height" type="xs:integer" minoccurs="0"/> <xs:element name="width" type="xs:integer" minoccurs="0"/> </xs:sequence> </xs:complextype> </xs:schema>

and need this:

<?xml version="1.0" encoding="utf-8"?> <resultset totalresultsavailable="1234" totalresultsreturned="1234" firstresultposition="1234"> <result type="resultset" minoccurs="0" maxoccurs="50"> <title type="xs:string"/> <summary type="xs:string"/> <url type="xs:string"/> <clickurl type="xs:string"/> <newssource type="xs:string"/> <newssourceurl type="xs:string"/> <language type="xs:string"/> <publishdate type="xs:string"/> <modificationdate type="xs:string" minoccurs="0"/> <thumbnail type="imagetype" minoccurs="0"> <url type="xs:string"/> <height type="xs:integer" minoccurs="0"/> <width type="xs:integer" minoccurs="0"/> </thumbnail> </result> </resultset>

i need api or if not exists, how do?

java parsing xml-parsing xsd schema

No comments:

Post a Comment