Given the following two xsds, which define an add element in
http://Component and a PersonType in
http://www.test.com/info...
<?php
$xmldas = SDO_DAS_XML::create('types.xsd');
$person =
$xmldas->createDataObject('
http://www.test.com/info','personType');
$name = $person->createDataObject('name');
$name->first = "Will";
$name->last = "Shakespeare";
$add = $xmldas->createDataObject('
http://Component','add');
$add->person = $person;
$xdoc = $xmldas->createDocument('', 'BOGUS', $add);
$xmlstr = $xmldas->saveString($xdoc, 2);
echo $xmlstr;
?>
types.xsd:
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:ns0="
http://www.test.com/info"
targetNamespace="
http://Component"
elementNameDefault="qualified">
<xs:import schemaLocation="person.xsd"
namespace="
http://www.test.com/info"/>
<xs:element name="add">
<xs:complexType>
<xs:sequence>
<xs:element name="person" type="ns0:personType"
nillable="true"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
person.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="
http://www.w3.org/2001/XMLSchema"
targetNamespace="
http://www.test.com/info"
xmlns:info="
http://www.test.com/info">
<complexType name="nameType">
<sequence>
<element name="first" type="string"></element>
<element name="last" type="string"></element>
</sequence>
</complexType>
<complexType name="personType">
<sequence>
<element name="name" type="info:nameType"></element>
</sequence>
</complexType>
</schema>
... if you now create a document with an 'add' element, create a PersonType object and assign meaningful first and last names, and serialise to XML, you get:
<?xml version="1.0" encoding="UTF-8"?>
<add xmlns="
http://Component" xmlns:tns="
http://Component" xmlns:tns2="
http://www.test.com/info" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">
<person>
<tns2:name>
<first>Will</first>
<last>Shakespeare</last>
</tns2:name>
</person>
</add>
There are several things wrong with this XML.
1. "name" should not be in tns2=
http://www.test.com/info, and neither should "first" and "last" be in the default namespace of
http://Component. The person.xsd has no elementFormDefault, so the elements below <person> should all be in the no name namespace.
2.You have to change the person.xsd to see the next thing: put ElementNameDefault="qualified" in
the person schema, then "name", "first" and "last" should all now be
coming out in the
http://www.test.com/info namespace, but it makes no
difference to the generated XML.
TUSCANY-1112