Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » finding elements or attributes based on Types
finding elements or attributes based on Types [message #36367] Wed, 21 January 2004 16:16 Go to next message
Eclipse User
Originally posted by: niemaz.xrce.xerox.com

Hi,
I'm trying to find out how to retrieve every elements or attributes that
are based on a global simpleTypeDefinition. I've tried with
findElementsUsingType but with no luck ;-(
For exemple, I'd like something that'd tell me that the simpleType
'atacharacType' is used in 'titi' (and others ...). 'titi' being an
attribute or an element.

<xs:simpleType name="atacharacType">
<xs:restriction base="xs:string">
<xs:pattern value="\d\d(-\d\d(-\d\d)?)?"/>
</xs:restriction>
</xs:simpleType>

<xs:element name="ata">
<xs:complexType>
<xs:sequence>
<xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>bla bla bla</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

thanx,

--mike
Re: finding elements or attributes based on Types [message #36417 is a reply to message #36367] Wed, 21 January 2004 20:36 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

--------------7B4B71396F9902438712601F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Mike,

The findElementsUsingType method only searches global element declarations but
in your example it's a local element declaration you want to find. There are
many ways to tackle this problem. This simple brute force approach will do
the trick for a given schema component:

for (Iterator i = xsdSchema.eAllContents(); i.hasNext(); )
{
Object o = i.next();
if (o instanceof XSDFeature)
{
XSDFeature xsdFeature = (XSDFeature)o;
if (xsdFeature.getType() == whatever)
{
// We have a matching element or attribute declaration.
}
}
}

It walks the schema containment tree looking for features (i.e., elements or
attributes) with a type that matches a specific type...


mike wrote:

> Hi,
> I'm trying to find out how to retrieve every elements or attributes that
> are based on a global simpleTypeDefinition. I've tried with
> findElementsUsingType but with no luck ;-(
> For exemple, I'd like something that'd tell me that the simpleType
> 'atacharacType' is used in 'titi' (and others ...). 'titi' being an
> attribute or an element.
>
> <xs:simpleType name="atacharacType">
> <xs:restriction base="xs:string">
> <xs:pattern value="\d\d(-\d\d(-\d\d)?)?"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:element name="ata">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
> <xs:annotation>
> <xs:documentation>bla bla bla</xs:documentation>
> </xs:annotation>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> thanx,
>
> --mike

--------------7B4B71396F9902438712601F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Mike,
<p>The findElementsUsingType method only searches global element declarations
but in your example it's a local element declaration you want to find.
There are many ways to tackle this problem.&nbsp; This simple brute force
approach will do the trick for a given schema component:
<blockquote>for (Iterator i = xsdSchema.eAllContents(); i.hasNext(); )
<br>{
<br>&nbsp; Object o = i.next();
<br>&nbsp; if (o instanceof XSDFeature)
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; XSDFeature xsdFeature = (XSDFeature)o;
<br>&nbsp;&nbsp;&nbsp; if (xsdFeature.getType() == whatever)
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // We have a matching element or attribute
declaration.
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp; }
<br>}</blockquote>
It walks the schema containment tree looking for features (i.e., elements
or attributes) with a type that matches a specific type...
<br>&nbsp;
<p>mike wrote:
<blockquote TYPE=CITE>Hi,
<br>&nbsp; I'm trying to find out how to retrieve every elements or attributes
that
<br>are based on a global simpleTypeDefinition. I've tried with
<br>findElementsUsingType but with no luck ;-(
<br>For exemple, I'd like something that'd tell me that the simpleType
<br>'atacharacType' is used in 'titi' (and others ...). 'titi' being an
<br>attribute or an element.
<p>&lt;xs:simpleType name="atacharacType">
<br>&nbsp;&lt;xs:restriction base="xs:string">
<br>&nbsp; &lt;xs:pattern value="\d\d(-\d\d(-\d\d)?)?"/>
<br>&nbsp;&lt;/xs:restriction>
<br>&lt;/xs:simpleType>
<p>&lt;xs:element name="ata">
<br>&nbsp;&lt;xs:complexType>
<br>&nbsp; &lt;xs:sequence>
<br>&nbsp;&nbsp; &lt;xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
<br>&nbsp;&nbsp;&nbsp; &lt;xs:annotation>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:documentation>bla bla bla&lt;/xs:documentation>
<br>&nbsp;&nbsp;&nbsp; &lt;/xs:annotation>
<br>&nbsp;&nbsp; &lt;/xs:element>
<br>&nbsp; &lt;/xs:sequence>
<br>&nbsp;&lt;/xs:complexType>
<br>&lt;/xs:element>
<p>thanx,
<p>--mike</blockquote>
</html>

--------------7B4B71396F9902438712601F--
Re: finding elements or attributes based on Types [message #36497 is a reply to message #36417] Thu, 22 January 2004 11:58 Go to previous message
Eclipse User
Originally posted by: niemaz.xrce.xerox.com

Thanx a lot,

--mike

nb: If the root schema is provided, would it look for elements inside
included schemas?

Ed Merks wrote:

> Mike,

> The findElementsUsingType method only searches global element declarations
but
> in your example it's a local element declaration you want to find. There are
> many ways to tackle this problem. This simple brute force approach will do
> the trick for a given schema component:

> for (Iterator i = xsdSchema.eAllContents(); i.hasNext(); )
> {
> Object o = i.next();
> if (o instanceof XSDFeature)
> {
> XSDFeature xsdFeature = (XSDFeature)o;
> if (xsdFeature.getType() == whatever)
> {
> // We have a matching element or attribute declaration.
> }
> }
> }

> It walks the schema containment tree looking for features (i.e., elements or
> attributes) with a type that matches a specific type...


> mike wrote:

> > Hi,
> > I'm trying to find out how to retrieve every elements or attributes that
> > are based on a global simpleTypeDefinition. I've tried with
> > findElementsUsingType but with no luck ;-(
> > For exemple, I'd like something that'd tell me that the simpleType
> > 'atacharacType' is used in 'titi' (and others ...). 'titi' being an
> > attribute or an element.
> >
> > <xs:simpleType name="atacharacType">
> > <xs:restriction base="xs:string">
> > <xs:pattern value="dd(-dd(-dd)?)?"/>
> > </xs:restriction>
> > </xs:simpleType>
> >
> > <xs:element name="ata">
> > <xs:complexType>
> > <xs:sequence>
> > <xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
> > <xs:annotation>
> > <xs:documentation>bla bla bla</xs:documentation>
> > </xs:annotation>
> > </xs:element>
> > </xs:sequence>
> > </xs:complexType>
> > </xs:element>
> >
> > thanx,
> >
> > --mike
Re: finding elements or attributes based on Types [message #583057 is a reply to message #36367] Wed, 21 January 2004 20:36 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26152
Registered: July 2009
Senior Member
--------------7B4B71396F9902438712601F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Mike,

The findElementsUsingType method only searches global element declarations but
in your example it's a local element declaration you want to find. There are
many ways to tackle this problem. This simple brute force approach will do
the trick for a given schema component:

for (Iterator i = xsdSchema.eAllContents(); i.hasNext(); )
{
Object o = i.next();
if (o instanceof XSDFeature)
{
XSDFeature xsdFeature = (XSDFeature)o;
if (xsdFeature.getType() == whatever)
{
// We have a matching element or attribute declaration.
}
}
}

It walks the schema containment tree looking for features (i.e., elements or
attributes) with a type that matches a specific type...


mike wrote:

> Hi,
> I'm trying to find out how to retrieve every elements or attributes that
> are based on a global simpleTypeDefinition. I've tried with
> findElementsUsingType but with no luck ;-(
> For exemple, I'd like something that'd tell me that the simpleType
> 'atacharacType' is used in 'titi' (and others ...). 'titi' being an
> attribute or an element.
>
> <xs:simpleType name="atacharacType">
> <xs:restriction base="xs:string">
> <xs:pattern value="\d\d(-\d\d(-\d\d)?)?"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:element name="ata">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
> <xs:annotation>
> <xs:documentation>bla bla bla</xs:documentation>
> </xs:annotation>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> thanx,
>
> --mike

--------------7B4B71396F9902438712601F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Mike,
<p>The findElementsUsingType method only searches global element declarations
but in your example it's a local element declaration you want to find.
There are many ways to tackle this problem.&nbsp; This simple brute force
approach will do the trick for a given schema component:
<blockquote>for (Iterator i = xsdSchema.eAllContents(); i.hasNext(); )
<br>{
<br>&nbsp; Object o = i.next();
<br>&nbsp; if (o instanceof XSDFeature)
<br>&nbsp; {
<br>&nbsp;&nbsp;&nbsp; XSDFeature xsdFeature = (XSDFeature)o;
<br>&nbsp;&nbsp;&nbsp; if (xsdFeature.getType() == whatever)
<br>&nbsp;&nbsp;&nbsp; {
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // We have a matching element or attribute
declaration.
<br>&nbsp;&nbsp;&nbsp; }
<br>&nbsp; }
<br>}</blockquote>
It walks the schema containment tree looking for features (i.e., elements
or attributes) with a type that matches a specific type...
<br>&nbsp;
<p>mike wrote:
<blockquote TYPE=CITE>Hi,
<br>&nbsp; I'm trying to find out how to retrieve every elements or attributes
that
<br>are based on a global simpleTypeDefinition. I've tried with
<br>findElementsUsingType but with no luck ;-(
<br>For exemple, I'd like something that'd tell me that the simpleType
<br>'atacharacType' is used in 'titi' (and others ...). 'titi' being an
<br>attribute or an element.
<p>&lt;xs:simpleType name="atacharacType">
<br>&nbsp;&lt;xs:restriction base="xs:string">
<br>&nbsp; &lt;xs:pattern value="\d\d(-\d\d(-\d\d)?)?"/>
<br>&nbsp;&lt;/xs:restriction>
<br>&lt;/xs:simpleType>
<p>&lt;xs:element name="ata">
<br>&nbsp;&lt;xs:complexType>
<br>&nbsp; &lt;xs:sequence>
<br>&nbsp;&nbsp; &lt;xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
<br>&nbsp;&nbsp;&nbsp; &lt;xs:annotation>
<br>&nbsp;&nbsp;&nbsp;&nbsp; &lt;xs:documentation>bla bla bla&lt;/xs:documentation>
<br>&nbsp;&nbsp;&nbsp; &lt;/xs:annotation>
<br>&nbsp;&nbsp; &lt;/xs:element>
<br>&nbsp; &lt;/xs:sequence>
<br>&nbsp;&lt;/xs:complexType>
<br>&lt;/xs:element>
<p>thanx,
<p>--mike</blockquote>
</html>

--------------7B4B71396F9902438712601F--
Re: finding elements or attributes based on Types [message #583100 is a reply to message #36417] Thu, 22 January 2004 11:58 Go to previous message
mike is currently offline mike
Messages: 35
Registered: July 2009
Member
Thanx a lot,

--mike

nb: If the root schema is provided, would it look for elements inside
included schemas?

Ed Merks wrote:

> Mike,

> The findElementsUsingType method only searches global element declarations
but
> in your example it's a local element declaration you want to find. There are
> many ways to tackle this problem. This simple brute force approach will do
> the trick for a given schema component:

> for (Iterator i = xsdSchema.eAllContents(); i.hasNext(); )
> {
> Object o = i.next();
> if (o instanceof XSDFeature)
> {
> XSDFeature xsdFeature = (XSDFeature)o;
> if (xsdFeature.getType() == whatever)
> {
> // We have a matching element or attribute declaration.
> }
> }
> }

> It walks the schema containment tree looking for features (i.e., elements or
> attributes) with a type that matches a specific type...


> mike wrote:

> > Hi,
> > I'm trying to find out how to retrieve every elements or attributes that
> > are based on a global simpleTypeDefinition. I've tried with
> > findElementsUsingType but with no luck ;-(
> > For exemple, I'd like something that'd tell me that the simpleType
> > 'atacharacType' is used in 'titi' (and others ...). 'titi' being an
> > attribute or an element.
> >
> > <xs:simpleType name="atacharacType">
> > <xs:restriction base="xs:string">
> > <xs:pattern value="dd(-dd(-dd)?)?"/>
> > </xs:restriction>
> > </xs:simpleType>
> >
> > <xs:element name="ata">
> > <xs:complexType>
> > <xs:sequence>
> > <xs:element name="titi" type="atacharacType" maxOccurs="unbounded">
> > <xs:annotation>
> > <xs:documentation>bla bla bla</xs:documentation>
> > </xs:annotation>
> > </xs:element>
> > </xs:sequence>
> > </xs:complexType>
> > </xs:element>
> >
> > thanx,
> >
> > --mike
Previous Topic:How to find out when an attribute is a ref or not?
Next Topic:How to find out when an attribute is a ref or not?
Goto Forum:
  


Current Time: Fri Oct 31 07:12:18 GMT 2014

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

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