473,657 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSD type derived via restriction in same namespace as restricted type?

In XML Schema, is it possible to derive a complex type via restriction
and have the new derived type be in a different namespace than the
original base type?

I've banged on this for 2 days now and I'm starting to think the
answer is no. I've searched this group and have not seen anything
discussing this.
>From Walmsley: "The values for the new type are a subset of those for
the base type. All values of the restricted type are also valid
according to the base type".

Now since all values of the restricted type are also valid according
to the base type, it follows that the namespace of the derived type
must be the same as the namespace of the base type. Otherwise the
instances of the derived type would not conform to the base type.

My question: Is it possible to derive a complex type via restriction
and have the new derived type be in a different namespace than the
original base type?

Sep 16 '07 #1
6 4269
Yes, it is possible.
The thing that you should take into account is that XML Schema
requires a different file to define a different namespace, so you
cannot derive the type and have it in a different namespace in the
same file as the base type.

Here you have an example:

base.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://www.oxygenxml.c om/ns/base">
<xs:simpleTyp e name="test">
<xs:restricti on base="xs:string ">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

restricted.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace ="http://www.oxygenxml.c om/ns/restricted"
xmlns:base="htt p://www.oxygenxml.c om/ns/base">
<xs:import namespace="http ://www.oxygenxml.c om/ns/base"
schemaLocation= "base.xsd"/>

<xs:simpleTyp e name="restricte dTest">
<xs:restricti on base="base:test ">
<xs:enumerati on value="val1"/>
<xs:enumerati on value="val2"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/
<oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Sep 17 '07 #2
Hi,

If you're talking about complex types, the type name itself can be in a
different namespace. But the child element names must be in the same
namespace (or no namespace in both types.)

So, if you are using elementFormDefa ult="qualified" , or you are using
the "ref" attribute to refer to globally declared elements, it won't
work to have the derived type in another namespace.

If you are using elementFormDefa ult="unqualifie d" and all your element
declarations are local, it can work.

Hope that helps,
Priscilla

-----------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (2001, Pren Hall)
XQuery (2007, O'Reilly Media)
http://www.datypic.com
http://www.xqueryfunctions.com
-----------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Sep 17 '07 #3
On 17 Sep, 15:38, Priscilla Walmsley <nos...@datypic .comwrote:
Hi,

If you're talking about complex types, the type name itself can be in a
different namespace. But the child element names must be in the same
namespace (or no namespace in both types.)

So, if you are using elementFormDefa ult="qualified" , or you are using
the "ref" attribute to refer to globally declared elements, it won't
work to have the derived type in another namespace.
Hi Priscilla,

Taking the case where the elements used the ref='' variant, would it
be OK in the above case to have the elements of the restricted type
echo the elements of the base type, and then restrict the attributes
associated with the complex type (assuming
attributeFormDe fault='false')?
If you are using elementFormDefa ult="unqualifie d" and all your element
declarations are local, it can work.
Cheers,

Pete.
=============== =============== ===============
Pete Cordell
Codalogic
for XML Schema to C++ data binding visit
http://codalogic.com/lmx/
=============== =============== ===============

Sep 17 '07 #4
Hi Pete,

Oh yes, sure - I didn't think of that case. If you are "ref"-ing the
element declarations that are in the original namespace, it's OK (they
can be the same child elements or a restricted set of those child
elements).

Its just if you were "ref"-ing element in the new namespace that would
cause a problem.

And yes, it works in a parallel way for attributes. If you use
attributeFormDe fault="unqualif ied" (the default behavior), you're fine.
If you're using attributes in namespaces, the attributes have to be in
the same namespace in the restricted type.

Thanks,
Priscilla

---------------------------------------------
Priscilla Walmsley
Author, XQuery (2007, O'Reilly Media)
http://www.datypic.com
http://www.xqueryfunctions.com
---------------------------------------------

*** Sent via Developersdex http://www.developersdex.com ***
Sep 17 '07 #5
On 17 Sep, 17:21, Priscilla Walmsley <nos...@datypic .comwrote:
Hi Pete,

Oh yes, sure - I didn't think of that case. If you are "ref"-ing the ...
Thanks Priscilla. I'll admit it was a pretty contrived case, and
probably not that useful, but I wanted to check my understanding.

Cheers,

Pete.
=============== =============== ===============
Pete Cordell
Codalogic
for XML Schema to C++ data binding visit
http://www.codalogic.com/lmx/
=============== =============== ===============

Sep 18 '07 #6
I made a few mistakes in my example XSDs/instances. I'm re-posting
FYI. I welcome any comments.

----------------------------------------------
XDSs for option 1
----------------------------------------------

-- Base XSD, filename BaseWithLocalEl ementDefs.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org/Base"
targetNamespace ="http://www.example.org/Base"
elementFormDefa ult="unqualifie d">

<xs:element name="A" type="AType" />
<xs:complexTy pe name="AType">
<xs:sequence>
<xs:element name="E1" type="xs:string " />
<xs:element name="E2" type="xs:string " minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>

-- Restricting XSD, with restricted types in different namespace.
filename RestrictionWith LocalElementDef s.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org/Restriction"
targetNamespace ="http://www.example.org/Restriction"
xmlns:base="htt p://www.example.org/Base"
elementFormDefa ult="unqualifie d">

<xs:import namespace="http ://www.example.org/Base"
schemaLocation= "BaseWithLocalE lementDefs.xsd" />

<xs:element name="ARestrict ed" type="ARestrict edType" />
<xs:complexTy pe name="ARestrict edType">
<xs:complexCont ent>
<xs:restricti on base="base:ATyp e">
<xs:sequence>
<xs:element name="E1" type="xs:string " />
</xs:sequence>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:schema>

-- Instance

<?xml version="1.0" encoding="UTF-8"?>
<res:ARestricte d xmlns:res="http ://www.example.org/Restriction"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocat ion="http://www.example.org/Restriction
RestrictionWith LocalElementDef s.xsd ">
<E1>E1</E1>
</res:ARestricted >
----------------------------------------------
XDSs for option 2
----------------------------------------------

-- Base XSD, filename BaseWithGlobalE lementDefs.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org/Base"
targetNamespace ="http://www.example.org/Base"
elementFormDefa ult="qualified" >

<xs:element name="E1" type="E1Type" />
<xs:simpleTyp e name="E1Type">
<xs:restricti on base="xs:string " />
</xs:simpleType>

<xs:element name="E2" type="E2Type" />
<xs:simpleTyp e name="E2Type">
<xs:restricti on base="xs:string " />
</xs:simpleType>

<xs:element name="A" type="AType" />
<xs:complexTy pe name="AType">
<xs:sequence>
<xs:element ref="E1" />
<xs:element ref="E2" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:schema>

-- Restricting XSD, filename RestrictionWith GlobalElementDe fs.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org/Restriction"
targetNamespace ="http://www.example.org/Restriction"
xmlns:base="htt p://www.example.org/Base"
elementFormDefa ult="qualified" >

<xs:import namespace="http ://www.example.org/Base"
schemaLocation= "BaseWithGlobal ElementDefs.xsd " />

<xs:element name="ARestrict ed" type="ARestrict edType" />
<xs:complexTy pe name="ARestrict edType">
<xs:complexCont ent>
<xs:restricti on base="base:ATyp e">
<xs:sequence>
<xs:element ref="base:E1" />
</xs:sequence>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:schema>

-- Instance

<?xml version="1.0" encoding="UTF-8"?>
<res:ARestricte d xmlns:res="http ://www.example.org/Restriction"
xmlns:base="htt p://www.example.org/Base"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocat ion="http://www.example.org/Restriction
RestrictionWith GlobalElementDe fs.xsd ">
<base:E1>E1</base:E1>
</res:ARestricted >
Sep 18 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8821
by: Stanimir Stamenkov | last post by:
Using Xerces2 Java I'm trying to validate a CSV data following an XNI example <http://xml.apache.org/xerces2-j/xni-config.html#examples>. The CSV scanner generates XML tree events like: <csv> <row> <col>Andy Clark</col> <col>16 Jan 1973</col> <col>Cincinnati</col>
2
1413
by: Brett Gerhardi | last post by:
Hi all, I'm trying to something that I'm sure must be possible within the schema language but I cannot seem to work it out. Briefly, I am defining a multi-tiered base structure - each tier has its own complextype defined with a base CT having the structure that others should follow. At the leaf ends of some areas I want to restrict the type of elements that are defined in restriction extended types but cannot find the correct way to...
1
7044
by: Tomi Laamanen | last post by:
we have problems in WebService -> .NET response Response look OK in XMLSpy and tcpTrace <m:AGW014N1Response xmlns:m="urn:com-softwareag-entirex-rpc:AGW014N1"><ArrayOfMAA SOAP-ENC:arrayType="MAA" xsi:type="SOAP-ENC:Array"><MAA><MAATUNNUS xsi:type="xsd:string">AT</MAATUNNUS><MAANIMI xsi:type="xsd:string">IT#VALTA</MAANIMI></MAA><MAA><MAATUNNUS xsi:type="xsd:string">BE</MAATUNNUS><MAANIMI...
1
18168
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it is serialized correctly, and the server returns a response (I've captured the response and it's correct!) but when the .NET deserialize this response, it throws the exception "System.InvalidOperationException: There is an error in XML
5
7270
by: hello | last post by:
How can I define the schema so that myage element has to be double or null? <xs:simpleType name="myage"> <xs:restriction base="xs:double"> <xs:enumeration value="null"/> </xs:restriction> </xs:simpleType> </xs:schema>
2
6577
by: Angel Of Death | last post by:
I have a method. It takes some XML as a parameter. Depending on the content of the XML it should create a specific object and call a KNOWN method. So: public void PersistXml(string XmlData){} I then determine what object I should call the Persist method on using a switch statement (not very OO). switch (otype)
1
1180
by: vusak | last post by:
Im thinking i may be attempting some kind of inbuilt cast or something, ideally i just want to overload the right functions so that the following occurs: -adding a node of the correct type causes the derived class overloaded virtual function to correctly add the node. -adding a node of the incorrect type defaults to the base class virtual function which reports a general invalid message. so my goal is to have a Node* type return an...
1
1674
by: Kenneth Stephen | last post by:
Hi, I have a primitive type int type which is restricted to the values of 0 to 23. Let me call the restricted type "HourType". I want to write out a list of the form: HourRangeType =HourType | HourType '-' HourType RangeList =HourRangeType ( ',' HourRangeType )*
6
1899
by: Generic Usenet Account | last post by:
I ran a small experiment involving RTTI and dynamic casting. Basically what I did was to cast a base class pointer to a derived type (yes, I know that is not kosher). I then performed dynamic_casting and I invoked RTTI. In both instances, the run time environment did not pick up the fact that what I was claiming to be a derived pointer was in fact the base pointer. However, when I invoked a virtual method using the ostensibly derived...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.