Sample Instance Generator and prefixes

Oxygen general issues.
chrisprobert
Posts: 6
Joined: Wed Nov 29, 2006 8:43 am

Sample Instance Generator and prefixes

Post by chrisprobert »

Hi,

I am currently evaluating v 8 and couldn't find any info on an issue I am having. So wondered if anyone could help me out. I am sure that I am missing something simple!
Basically I want to generate a sample based on a multi namespace schema. When I go to do this, there is a table which lists prefixes/namespace mappings, and the help says that I should be able to add to this, but I can't. I only see the root namespace, and cannot add any more, so when I generate I get xmlns attributes with full uri's on every element that is not in the root namespace (nearly everything).
Is there a button I am missing that allows one to add namespaces and prefixes to the list in the XML Sample Generator dialog?

Thanks,

Chris
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

The table with prefix/namespace mappings lists the namespaces declared in your XML Schema. In this table you can edit the prefix used for each namespace in a generated XML instance by double clicking on a table row. The table does not allow adding other namespaces because it lists all the namespaces declared in your schema. Why do you want to add a namespace that is not declared in your schema ?


Regards,
Sorin
chrisprobert
Posts: 6
Joined: Wed Nov 29, 2006 8:43 am

Post by chrisprobert »

Hi, and thanks for the swift response!

Well, I don't want to add ones that are not in my schema, and you are right, I can't think of any reason I would need to! But it is for some reason not picking up my decalred namespaces, so I guess that is the root issue.
Do you know what mechanism is used for this? They are certainly declared and imported, but then do not appear in the list. The schema in question is rather huge and complex and so below is an example which will demonstrate the issue, if you stick them in the same folder, open Test.xsd and try to generate an instance based on "TestRoot":

Schema Test.xsd:

Code: Select all


<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:example-com:1"
xmlns:ns2="urn:example-com:2"
targetNamespace="urn:example-com:1"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
version="1.0">

<xsd:import schemaLocation="Test2.xsd" namespace="urn:example-com:2" />

<xsd:element name="TestRoot" type="TestRootType"/>

<xsd:complexType name="TestRootType">
<xsd:sequence>
<xsd:element name="TestElem1" type="TestType1"/>
<xsd:element name="TestElem2" type="ns2:TestType2"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="TestType1">
<xsd:sequence>
<xsd:element name="SomeDate" type="xsd:dateTime"/>
<xsd:element name="SomeNumber" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>
Schema Test2.xsd

Code: Select all


<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:example-com:2"
targetNamespace="urn:example-com:2"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
version="1.0">


<xsd:complexType name="TestType2">
<xsd:sequence>
<xsd:element name="SomeData1" type="xsd:string"/>
<xsd:element name="SomeData2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>


</xsd:schema>
Instance output:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<TestRoot xmlns="urn:example-com:1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:example-com:1 file:/C:/chris_testing/oxygen/Test.xsd">
<TestElem1>
<SomeDate>2006-05-04T18:13:51.0Z</SomeDate>
<SomeNumber>0</SomeNumber>
</TestElem1>
<TestElem2>
<SomeData1 xmlns="urn:example-com:2">SomeData10</SomeData1>
<SomeData2 xmlns="urn:example-com:2">SomeData20</SomeData2>
</TestElem2>
</TestRoot>
And finally the output I would like!:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<TestRoot xmlns="urn:example-com:1"
xmlns:ns2="urn:example-com:2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:example-com:1 file:/C:/chris_testing/oxygen/Test.xsd">
<TestElem1>
<SomeDate>2006-05-04T18:13:51.0Z</SomeDate>
<SomeNumber>0</SomeNumber>
</TestElem1>
<TestElem2>
<ns2:SomeData1>SomeData10</ns2:SomeData1>
<ns2:SomeData2>SomeData20</ns2:SomeData2>
</TestElem2>
</TestRoot>

Cheers,

Chris
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Thank you for the example. The namespace is not added to the table of mappings if the schema file for that namespace does not declare global elements. We will fix the problem in the next version of oXygen. You can workaround this by adding a dummy global element in Test2.xsd:

Code: Select all

<xsd:element name="dummy"/>

Regards,
Sorin
chrisprobert
Posts: 6
Joined: Wed Nov 29, 2006 8:43 am

Post by chrisprobert »

Hi Sorin,

That explains it.. thanks... Dummy element will work fine for now, but I look forward to the fix. Separating out common Types into into it's own schema is not uncommon amongst larger schema libraries.

Many thanks,

Chris
Post Reply