Page 1 of 1

Generating XML from XSD Schema

Posted: Thu Oct 22, 2009 6:29 pm
by ados1984@gmail.com
Hello,

I am trying to generate XML from XSD Schema using Generate Sample XML Files, when I try to do so than it is asking me for the root element which I suppose is already present in my schema as <schema></schema> and am stuck with the issue and would certainly appreciate if any one can provide some useful insights on the matter.


Thanks.

Re: Generating XML from XSD Schema

Posted: Fri Oct 23, 2009 9:42 am
by tavy
Hello,

The root element you should provide is for the XML file that you want to generate. Probably you do not have a global element defined in your schema. To make it work you should define a global element in your schema.
You can read more about XML Schema Instance Generator in <oXygen/> User Manual.

Do not hesitate to contact us if you have any further questions.

Best Regards,
Octavian Nadolu

Re: Generating XML from XSD Schema

Posted: Fri Oct 23, 2009 5:41 pm
by ados1984@gmail.com
I have an xsd which has 3 imports to another xsd, 8 complex types and 3 simple types.

Now of this I have to work on only 1 compex type, which in turn inherits many other XSD - mainly the 3 imports which current xsd's has.

I will be getting XML file containing data only according to 1 complex type only, which I have mentioned.

Now am trying to generate sample XML file which contains data according to single complex type and am trying to validate it, but when I try to do so using XMLSpy or OxygenXML it says that root node is not defined.

Now, when I try to define root nodes it does not allow me to do so and if I try to create another xsd just for this complex type than also it gives me some errors as inherited xsd which this complex type points to in initial xsd is not working in new one, I tried to inherit 3 xsd's to which complex type point to in initial xsd in new xsd but still it is not working.

Also my another question is - Can we validate XML file against some part of XSD as compared to complete XSD because XML what am getting is according to 1 complex element type in XSD ?


Format of Initial XSD:


Code: Select all

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

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:schema location targetNamespace=targetnamespace elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.652">
<xs:import namespace=first xsd which is imported>
<xs:import namespace=second xsd which is imported>
<xs:import namespace=third xsd which is imported>
<xs:complexType name="firstcomplextype" abstract="false">
<xs:sequence>
<xs:element name="some value" type="xs:string" minOccurs="0"/>
<xs:element name="some value" type="some value"/>
<xs:element name="some value" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="some value" type="xs:int" use="required"/>
<xs:attribute name="some value" type="xs:value" use="required"/>
<xs:attribute name="some value" type="xs:int" use="required"/>
</xs:complexType>
<xs:complexType name="second complex type" abstract="false">
<xs:sequence>
<xs:element name="some value" type="xs:some value" minOccurs="0"/>
<xs:element name="some value" type="xs:some value" minOccurs="0"/>
<xs:element name="some value" type="some value"/>
<xs:element name="some value" type="some value"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="third complex type**I need to work with only this complex type and xml file will contain data according to this complex type only and I need to validate incoming XML against only this complex type**" abstract="false">
<xs:sequence>
<xs:element name="some value" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="some value" type="some value" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="some value" type="some value"/>
<xs:element name="some value" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="some value" type="some value" minOccurs="0" maxOccurs="unbounded"/>---**Here this particular element points to another XSD, one of the imported XSD's**
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:sequence minOccurs="0">
<xs:element name="some value" type="xs:some value" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="some value" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="some value" type="some value" minOccurs="0" maxOccurs="unbounded"/>---**Here this particular element points to another XSD, one of the imported XSD's**
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:sequence minOccurs="0">
<xs:element name="some value" type="xs:some value" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="some value" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="some value" type="some value" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType name="4th complex type" abstract="false">
<xs:sequence>
<xs:element name="elements">
<xs:complexType>
<xs:sequence>
<xs:element name="some value" type="some value" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
and the xsd continues as it has many more complex types and simple types. Any guidance would be highly appreciated.

Re: Generating XML from XSD Schema

Posted: Mon Oct 26, 2009 10:48 am
by tavy
Hello,

You need to add an element in your schema that has as type the complex type you want to work with. The element declaration looks like this:

Code: Select all

<xs:element name="newElement" type="thirdComplexType"/>
You can declare your element directly in the current schema (the one you give us as example) or you can create a new schema that imports the current one and declare the element there.

The generated XML file will be validated against the complex type "thirdComplexType" because it will have "newElement" as root element. In other words the XML file is automatically validated against some part of the XSD.

You can read more about XML Schema here:
http://www.zvon.org/xxl/XMLSchemaTutori ... eries.html
http://www.w3schools.com/Schema/default.asp

Best Regards,
Octavian Nadolu

Re: Generating XML from XSD Schema

Posted: Mon Oct 26, 2009 7:00 pm
by ados1984@gmail.com
Thank you very much Sir for providing useful information about my case. I have implemented as you suggested and it really worked fine for me.