Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Finding type-references of local-elements
Finding type-references of local-elements [message #6853] Mon, 18 November 2002 16:34 Go to next message
Eclipse UserFriend
Originally posted by: thomas.hoffmann.i-one.at

Hi!

I have a problem to get the complex-type-definition of a locally-defined
element, which uses a reference to a complex type.
For example:

I have a schema (listing at the end of this posting) and I want to get the
the complex-Type-Definition of the testlecturer-element (the fifth
xsd-element under the rootelement "lva").
With
schema.resolveElementDeclaration(c_schema.getTargetNamespace (), "testlecturer
") I get an XSDElementDeclaration.

Using the toString() method leads to the following output.
org.eclipse.xsd.impl.XSDElementDeclarationImpl@439a20 (element: null) (name:
testlecturer, targetNamespace: http://www.infosys.tuwien.ac.at/ns/xml)
(value: null, constraint: <unset>, form: <unset>, lexicalValue: null)
(nillable: <unset>, disallowedSubstitutions: null,
substitutionGroupExclusions: null, abstract: <unset>, lexicalFinal: null,
block: null).

So I am not able to receive a valid XSDTypeDefinition-Objekt with
elem.getTypeDefinition() because the Type-Definition is null;

The testlecturer-element is also not available in the
Element-Declarations-List which you get with
schema.getElementDeclarations(). Why?

Has anyone an idea how I can get the complex-type-definition of testlecturer
when I have only the name of the element ("testlecturer") and the namespace?

Thanks in advance,
Tom.

________________schema_____________________
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.infosys.tuwien.ac.at/ns/xml"
xmlns:targetNS="http://www.infosys.tuwien.ac.at/ns/xml"
>

<xsd:element name="lva">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="targetNS:contents" minOccurs="1"
maxOccurs="1" />
<xsd:element ref="targetNS:lecturer" minOccurs="1" maxOccurs="1"
/>
<xsd:element ref="targetNS:grading" minOccurs="1" maxOccurs="1"
/>
<xsd:element ref="targetNS:students" minOccurs="1" maxOccurs="1"
/>

<xsd:element name="testlecturer" type="targetNS:SimplePerson" />


</xsd:sequence>
<xsd:attribute name="lvatype" type="targetNS:lvatype" default="VO"
use="optional" />
<xsd:attribute name="number" type="xsd:integer" use="required" />
</xsd:complexType>
</xsd:element>

<xsd:element name="grading" type="xsd:string" fixed="very good" />

<xsd:complexType name="SimplePerson">
<xsd:sequence>
<xsd:element ref="targetNS:firstname" />
<xsd:element ref="targetNS:lastname" />
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="ComplexPerson">
<xsd:complexContent>
<xsd:extension base="targetNS:SimplePerson">
<xsd:sequence>
<xsd:element form="qualified" name="street" type="xsd:string" />
<xsd:element form="qualified" name="email" type="targetNS:MyEmail"
/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="contents">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="targetNS:overview" minOccurs="0" maxOccurs="1" />
<xsd:element ref="targetNS:item" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:simpleType name="lvatype">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="VO" />
<xsd:enumeration value="VU" />
<xsd:enumeration value="LU" />
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="MyEmail">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\p{L}{2,}@\p{L}{1,}(.\p{L}{1,})*"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:element name="overview" type="xsd:string" />

<xsd:element name="item" type="xsd:string" />

<xsd:element name="lecturer" type="targetNS:SimplePerson" />

<xsd:element name="students">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="targetNS:student" minOccurs="1" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name="student" type="targetNS:ComplexPerson" />

<xsd:element name="firstname" type="xsd:string" />

<xsd:element name="lastname" type="xsd:string" />

</xsd:schema>
_________________________________________________
Re: Finding type-references of local-elements [message #6879 is a reply to message #6853] Mon, 18 November 2002 18:27 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Thomas,

Only global element declarations will appear in a schema's
getElementDeclarations and only global element declarations can be resolved
given just a namespace and a local name.

Your element "testlecturer" is a local element declaration. To resolve it
correctly, a context specifying a complex type definition is needed in addition
to a namespace and a local name. I.e., you need to search the complex type
definition's particles to resolve the namespace and local name to an element
declaration. (It may occur more than once in the content, but each occurrence
is required to have the identical type.) There is no convenience method to
perform this lookup.

Thomas Hoffmann wrote:

> Hi!
>
> I have a problem to get the complex-type-definition of a locally-defined
> element, which uses a reference to a complex type.
> For example:
>
> I have a schema (listing at the end of this posting) and I want to get the
> the complex-Type-Definition of the testlecturer-element (the fifth
> xsd-element under the rootelement "lva").
> With
> schema.resolveElementDeclaration(c_schema.getTargetNamespace (), "testlecturer
> ") I get an XSDElementDeclaration.
>
> Using the toString() method leads to the following output.
> org.eclipse.xsd.impl.XSDElementDeclarationImpl@439a20 (element: null) (name:
> testlecturer, targetNamespace: http://www.infosys.tuwien.ac.at/ns/xml)
> (value: null, constraint: <unset>, form: <unset>, lexicalValue: null)
> (nillable: <unset>, disallowedSubstitutions: null,
> substitutionGroupExclusions: null, abstract: <unset>, lexicalFinal: null,
> block: null).
>
> So I am not able to receive a valid XSDTypeDefinition-Objekt with
> elem.getTypeDefinition() because the Type-Definition is null;
>
> The testlecturer-element is also not available in the
> Element-Declarations-List which you get with
> schema.getElementDeclarations(). Why?
>
> Has anyone an idea how I can get the complex-type-definition of testlecturer
> when I have only the name of the element ("testlecturer") and the namespace?
>
> Thanks in advance,
> Tom.
>
> ________________schema_____________________
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.infosys.tuwien.ac.at/ns/xml"
> xmlns:targetNS="http://www.infosys.tuwien.ac.at/ns/xml"
> >
>
> <xsd:element name="lva">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="targetNS:contents" minOccurs="1"
> maxOccurs="1" />
> <xsd:element ref="targetNS:lecturer" minOccurs="1" maxOccurs="1"
> />
> <xsd:element ref="targetNS:grading" minOccurs="1" maxOccurs="1"
> />
> <xsd:element ref="targetNS:students" minOccurs="1" maxOccurs="1"
> />
>
> <xsd:element name="testlecturer" type="targetNS:SimplePerson" />
>
> </xsd:sequence>
> <xsd:attribute name="lvatype" type="targetNS:lvatype" default="VO"
> use="optional" />
> <xsd:attribute name="number" type="xsd:integer" use="required" />
> </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="grading" type="xsd:string" fixed="very good" />
>
> <xsd:complexType name="SimplePerson">
> <xsd:sequence>
> <xsd:element ref="targetNS:firstname" />
> <xsd:element ref="targetNS:lastname" />
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="ComplexPerson">
> <xsd:complexContent>
> <xsd:extension base="targetNS:SimplePerson">
> <xsd:sequence>
> <xsd:element form="qualified" name="street" type="xsd:string" />
> <xsd:element form="qualified" name="email" type="targetNS:MyEmail"
> />
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:element name="contents">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="targetNS:overview" minOccurs="0" maxOccurs="1" />
> <xsd:element ref="targetNS:item" minOccurs="1" maxOccurs="unbounded" />
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> <xsd:simpleType name="lvatype">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="VO" />
> <xsd:enumeration value="VU" />
> <xsd:enumeration value="LU" />
> </xsd:restriction>
> </xsd:simpleType>
>
> <xsd:simpleType name="MyEmail">
> <xsd:restriction base="xsd:string">
> <xsd:pattern value="\p{L}{2,}@\p{L}{1,}(.\p{L}{1,})*"/>
> </xsd:restriction>
> </xsd:simpleType>
>
> <xsd:element name="overview" type="xsd:string" />
>
> <xsd:element name="item" type="xsd:string" />
>
> <xsd:element name="lecturer" type="targetNS:SimplePerson" />
>
> <xsd:element name="students">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="targetNS:student" minOccurs="1" maxOccurs="unbounded" />
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="student" type="targetNS:ComplexPerson" />
>
> <xsd:element name="firstname" type="xsd:string" />
>
> <xsd:element name="lastname" type="xsd:string" />
>
> </xsd:schema>
> _________________________________________________

--
Ed Merks
Re: Finding type-references of local-elements [message #563868 is a reply to message #6853] Mon, 18 November 2002 18:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Thomas,

Only global element declarations will appear in a schema's
getElementDeclarations and only global element declarations can be resolved
given just a namespace and a local name.

Your element "testlecturer" is a local element declaration. To resolve it
correctly, a context specifying a complex type definition is needed in addition
to a namespace and a local name. I.e., you need to search the complex type
definition's particles to resolve the namespace and local name to an element
declaration. (It may occur more than once in the content, but each occurrence
is required to have the identical type.) There is no convenience method to
perform this lookup.

Thomas Hoffmann wrote:

> Hi!
>
> I have a problem to get the complex-type-definition of a locally-defined
> element, which uses a reference to a complex type.
> For example:
>
> I have a schema (listing at the end of this posting) and I want to get the
> the complex-Type-Definition of the testlecturer-element (the fifth
> xsd-element under the rootelement "lva").
> With
> schema.resolveElementDeclaration(c_schema.getTargetNamespace (), "testlecturer
> ") I get an XSDElementDeclaration.
>
> Using the toString() method leads to the following output.
> org.eclipse.xsd.impl.XSDElementDeclarationImpl@439a20 (element: null) (name:
> testlecturer, targetNamespace: http://www.infosys.tuwien.ac.at/ns/xml)
> (value: null, constraint: <unset>, form: <unset>, lexicalValue: null)
> (nillable: <unset>, disallowedSubstitutions: null,
> substitutionGroupExclusions: null, abstract: <unset>, lexicalFinal: null,
> block: null).
>
> So I am not able to receive a valid XSDTypeDefinition-Objekt with
> elem.getTypeDefinition() because the Type-Definition is null;
>
> The testlecturer-element is also not available in the
> Element-Declarations-List which you get with
> schema.getElementDeclarations(). Why?
>
> Has anyone an idea how I can get the complex-type-definition of testlecturer
> when I have only the name of the element ("testlecturer") and the namespace?
>
> Thanks in advance,
> Tom.
>
> ________________schema_____________________
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://www.infosys.tuwien.ac.at/ns/xml"
> xmlns:targetNS="http://www.infosys.tuwien.ac.at/ns/xml"
> >
>
> <xsd:element name="lva">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="targetNS:contents" minOccurs="1"
> maxOccurs="1" />
> <xsd:element ref="targetNS:lecturer" minOccurs="1" maxOccurs="1"
> />
> <xsd:element ref="targetNS:grading" minOccurs="1" maxOccurs="1"
> />
> <xsd:element ref="targetNS:students" minOccurs="1" maxOccurs="1"
> />
>
> <xsd:element name="testlecturer" type="targetNS:SimplePerson" />
>
> </xsd:sequence>
> <xsd:attribute name="lvatype" type="targetNS:lvatype" default="VO"
> use="optional" />
> <xsd:attribute name="number" type="xsd:integer" use="required" />
> </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="grading" type="xsd:string" fixed="very good" />
>
> <xsd:complexType name="SimplePerson">
> <xsd:sequence>
> <xsd:element ref="targetNS:firstname" />
> <xsd:element ref="targetNS:lastname" />
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="ComplexPerson">
> <xsd:complexContent>
> <xsd:extension base="targetNS:SimplePerson">
> <xsd:sequence>
> <xsd:element form="qualified" name="street" type="xsd:string" />
> <xsd:element form="qualified" name="email" type="targetNS:MyEmail"
> />
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <xsd:element name="contents">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="targetNS:overview" minOccurs="0" maxOccurs="1" />
> <xsd:element ref="targetNS:item" minOccurs="1" maxOccurs="unbounded" />
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> <xsd:simpleType name="lvatype">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="VO" />
> <xsd:enumeration value="VU" />
> <xsd:enumeration value="LU" />
> </xsd:restriction>
> </xsd:simpleType>
>
> <xsd:simpleType name="MyEmail">
> <xsd:restriction base="xsd:string">
> <xsd:pattern value="\p{L}{2,}@\p{L}{1,}(.\p{L}{1,})*"/>
> </xsd:restriction>
> </xsd:simpleType>
>
> <xsd:element name="overview" type="xsd:string" />
>
> <xsd:element name="item" type="xsd:string" />
>
> <xsd:element name="lecturer" type="targetNS:SimplePerson" />
>
> <xsd:element name="students">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element ref="targetNS:student" minOccurs="1" maxOccurs="unbounded" />
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
>
> <xsd:element name="student" type="targetNS:ComplexPerson" />
>
> <xsd:element name="firstname" type="xsd:string" />
>
> <xsd:element name="lastname" type="xsd:string" />
>
> </xsd:schema>
> _________________________________________________

--
Ed Merks


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Finding type-references of local-elements
Next Topic:UML diagram in the JavaDoc of the XSD project
Goto Forum:
  


Current Time: Fri Apr 26 20:02:19 GMT 2024

Powered by FUDForum. Page generated in 0.04450 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top