Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » How to retrieve Attributes for a complex ElementDeclaration
How to retrieve Attributes for a complex ElementDeclaration [message #51267] Mon, 23 August 2004 21:51 Go to next message
Eclipse User
Originally posted by: gj.puredge.com

Hi,

Given the schema fragment:

<xsd:element name="Test">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="comment"></xsd:element>
<xsd:element name="choice2" type="xsd:string"></xsd:element>
</xsd:choice>
<xsd:attribute name="Attribute" type="xsd:string"></xsd:attribute>
</xsd:complexType>
</xsd:element>

From the complexType particle, getTerm() gets the "choice" ModelGroup.
Which method gets the attribute(s)?

Sorry for such a newbie question.

Thanks
Re: How to retrieve Attributes for a complex ElementDeclaration [message #51293 is a reply to message #51267] Tue, 24 August 2004 03:15 Go to previous messageGo to next message
Eclipse User
Originally posted by: gj.pureedge.com

I think I found what I need. Here's some code I wrote to print out
attributes for an element. Correct me if I'm wrong.

Starting with: ElementDeclaration element

XSDTypeDefinition type = element.getTypeDefinition();

if (type instanceof XSDComplexTypeDefinition)
{
EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();

for (Iterator iter = list.iterator(); iter.hasNext();)
{
Object obj = iter.next();
if (obj instanceof XSDAttributeUse)
{
XSDAttributeUse a = (XSDAttributeUse) obj;
System.out.println(a.getAttributeDeclaration().getName());
}
}
}

I'm not sure if the results of getAttributeContents() are always an instance
of XSDAttributeUse so I check just in case.
Re: How to retrieve Attributes for a complex ElementDeclaration [message #51458 is a reply to message #51293] Tue, 24 August 2004 11:48 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

Gary,

Yes, the contents will always be of type XSDAttributeUse, so there's no
need for a instanceof check. Note that getAttributeContents returns the
physically contained attribute declarations whereas getAttributeUses
will get the inherited ones as well as the local ones just as getContent
returns the physically contained content model (particle/simple type)
whereas getContentType will return the inherited content model as well.


Gary J wrote:

>I think I found what I need. Here's some code I wrote to print out
>attributes for an element. Correct me if I'm wrong.
>
>Starting with: ElementDeclaration element
>
> XSDTypeDefinition type = element.getTypeDefinition();
>
> if (type instanceof XSDComplexTypeDefinition)
> {
> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>
> for (Iterator iter = list.iterator(); iter.hasNext();)
> {
> Object obj = iter.next();
> if (obj instanceof XSDAttributeUse)
> {
> XSDAttributeUse a = (XSDAttributeUse) obj;
> System.out.println(a.getAttributeDeclaration().getName());
> }
> }
> }
>
>I'm not sure if the results of getAttributeContents() are always an instance
>of XSDAttributeUse so I check just in case.
>
>
>
>
Re: How to retrieve Attributes for a complex ElementDeclaration [message #51512 is a reply to message #51458] Tue, 24 August 2004 14:32 Go to previous messageGo to next message
Eclipse User
Originally posted by: gj.pureedge.com

Thanks Ed,

getAttributeContents vs getAttributeUses

Am I correct that this is another example of the difference between the
"Concrete" and "Abstract" representations of the schema?

The Concrete representation is what's actually written in the schema file
itself whereas Abstract is (sort of) the "expanded" version of the schema
with all the inherited types, groups, refs, etc available.

I'd use the Concrete model if I wanted to serialize (write) the schema and
the Abstract to walk the schema elements, among other things.

I think I'm actually starting to get a clue. That perhaps qualifies me a
"cluebie" .




"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cgf9ov$ujg$1@eclipse.org...
Gary,

Yes, the contents will always be of type XSDAttributeUse, so there's no
need for a instanceof check. Note that getAttributeContents returns the
physically contained attribute declarations whereas getAttributeUses
will get the inherited ones as well as the local ones just as getContent
returns the physically contained content model (particle/simple type)
whereas getContentType will return the inherited content model as well.


Gary J wrote:

>I think I found what I need. Here's some code I wrote to print out
>attributes for an element. Correct me if I'm wrong.
>
>Starting with: ElementDeclaration element
>
> XSDTypeDefinition type = element.getTypeDefinition();
>
> if (type instanceof XSDComplexTypeDefinition)
> {
> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>
> for (Iterator iter = list.iterator(); iter.hasNext();)
> {
> Object obj = iter.next();
> if (obj instanceof XSDAttributeUse)
> {
> XSDAttributeUse a = (XSDAttributeUse) obj;
> System.out.println(a.getAttributeDeclaration().getName());
> }
> }
> }
>
>I'm not sure if the results of getAttributeContents() are always an
>instance
>of XSDAttributeUse so I check just in case.
>
>
>
>
Re: How to retrieve Attributes for a complex ElementDeclaration [message #51538 is a reply to message #51512] Tue, 24 August 2004 14:37 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------020405000909090205010801
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

Yes, that's exactly right. ;-)


Gary J wrote:

>Thanks Ed,
>
>getAttributeContents vs getAttributeUses
>
>Am I correct that this is another example of the difference between the
>"Concrete" and "Abstract" representations of the schema?
>
>The Concrete representation is what's actually written in the schema file
>itself whereas Abstract is (sort of) the "expanded" version of the schema
>with all the inherited types, groups, refs, etc available.
>
>I'd use the Concrete model if I wanted to serialize (write) the schema and
>the Abstract to walk the schema elements, among other things.
>
>I think I'm actually starting to get a clue. That perhaps qualifies me a
>"cluebie" .
>
>
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cgf9ov$ujg$1@eclipse.org...
>Gary,
>
>Yes, the contents will always be of type XSDAttributeUse, so there's no
>need for a instanceof check. Note that getAttributeContents returns the
>physically contained attribute declarations whereas getAttributeUses
>will get the inherited ones as well as the local ones just as getContent
>returns the physically contained content model (particle/simple type)
>whereas getContentType will return the inherited content model as well.
>
>
>Gary J wrote:
>
>
>
>>I think I found what I need. Here's some code I wrote to print out
>>attributes for an element. Correct me if I'm wrong.
>>
>>Starting with: ElementDeclaration element
>>
>>XSDTypeDefinition type = element.getTypeDefinition();
>>
>>if (type instanceof XSDComplexTypeDefinition)
>> {
>> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>>
>> for (Iterator iter = list.iterator(); iter.hasNext();)
>> {
>> Object obj = iter.next();
>> if (obj instanceof XSDAttributeUse)
>> {
>> XSDAttributeUse a = (XSDAttributeUse) obj;
>> System.out.println(a.getAttributeDeclaration().getName());
>> }
>> }
>> }
>>
>>I'm not sure if the results of getAttributeContents() are always an
>>instance
>>of XSDAttributeUse so I check just in case.
>>
>>
>>
>>
>>
>>
>
>
>
>


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

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
Yes, that's exactly right. ;-)<br>
<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcgfjbg$i5q$1@eclipse.org" type="cite">
<pre wrap="">Thanks Ed,

getAttributeContents vs getAttributeUses

Am I correct that this is another example of the difference between the
"Concrete" and "Abstract" representations of the schema?

The Concrete representation is what's actually written in the schema file
itself whereas Abstract is (sort of) the "expanded" version of the schema
with all the inherited types, groups, refs, etc available.

I'd use the Concrete model if I wanted to serialize (write) the schema and
the Abstract to walk the schema elements, among other things.

I think I'm actually starting to get a clue. That perhaps qualifies me a
"cluebie" .




"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cgf9ov$ujg$1@eclipse.org">news:cgf9ov$ujg$1@eclipse.org</a>...
Gary,

Yes, the contents will always be of type XSDAttributeUse, so there's no
need for a instanceof check. Note that getAttributeContents returns the
physically contained attribute declarations whereas getAttributeUses
will get the inherited ones as well as the local ones just as getContent
returns the physically contained content model (particle/simple type)
whereas getContentType will return the inherited content model as well.


Gary J wrote:

</pre>
<blockquote type="cite">
<pre wrap="">I think I found what I need. Here's some code I wrote to print out
attributes for an element. Correct me if I'm wrong.

Starting with: ElementDeclaration element

XSDTypeDefinition type = element.getTypeDefinition();

if (type instanceof XSDComplexTypeDefinition)
{
EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();

for (Iterator iter = list.iterator(); iter.hasNext();)
{
Object obj = iter.next();
if (obj instanceof XSDAttributeUse)
{
XSDAttributeUse a = (XSDAttributeUse) obj;
System.out.println(a.getAttributeDeclaration().getName());
}
}
}

I'm not sure if the results of getAttributeContents() are always an
instance
of XSDAttributeUse so I check just in case.




</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------020405000909090205010801--
attribute use from declaration [message #54280 is a reply to message #51538] Wed, 27 October 2004 06:49 Go to previous messageGo to next message
Eclipse User
Originally posted by: user.domain.invalid

Sorry to drop this question..may be stupid one

How can one get XSDAttributeUse for an attribute from attributedeclaration.

best

roy

Ed Merks wrote:
> Gary,
>
> Yes, that's exactly right. ;-)
>
>
> Gary J wrote:
>
>>Thanks Ed,
>>
>>getAttributeContents vs getAttributeUses
>>
>>Am I correct that this is another example of the difference between the
>>"Concrete" and "Abstract" representations of the schema?
>>
>>The Concrete representation is what's actually written in the schema file
>>itself whereas Abstract is (sort of) the "expanded" version of the schema
>>with all the inherited types, groups, refs, etc available.
>>
>>I'd use the Concrete model if I wanted to serialize (write) the schema and
>>the Abstract to walk the schema elements, among other things.
>>
>>I think I'm actually starting to get a clue. That perhaps qualifies me a
>>"cluebie" .
>>
>>
>>
>>
>>"Ed Merks" <merks@ca.ibm.com> wrote in message
>>news:cgf9ov$ujg$1@eclipse.org...
>>Gary,
>>
>>Yes, the contents will always be of type XSDAttributeUse, so there's no
>>need for a instanceof check. Note that getAttributeContents returns the
>>physically contained attribute declarations whereas getAttributeUses
>>will get the inherited ones as well as the local ones just as getContent
>>returns the physically contained content model (particle/simple type)
>>whereas getContentType will return the inherited content model as well.
>>
>>
>>Gary J wrote:
>>
>>
>>
>>>I think I found what I need. Here's some code I wrote to print out
>>>attributes for an element. Correct me if I'm wrong.
>>>
>>>Starting with: ElementDeclaration element
>>>
>>>XSDTypeDefinition type = element.getTypeDefinition();
>>>
>>>if (type instanceof XSDComplexTypeDefinition)
>>> {
>>> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>>>
>>> for (Iterator iter = list.iterator(); iter.hasNext();)
>>> {
>>> Object obj = iter.next();
>>> if (obj instanceof XSDAttributeUse)
>>> {
>>> XSDAttributeUse a = (XSDAttributeUse) obj;
>>> System.out.println(a.getAttributeDeclaration().getName());
>>> }
>>> }
>>> }
>>>
>>>I'm not sure if the results of getAttributeContents() are always an
>>>instance
>>>of XSDAttributeUse so I check just in case.
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>
Re: attribute use from declaration [message #54307 is a reply to message #54280] Wed, 27 October 2004 17:00 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

Roy,

If the attribute use is not the container
(XSDConcreteComponent.getContainer()) of the attribute declaration, then
there isn't a way since there can be arbitrarily many attributes uses
that share a particular attribute declaration (because they have "ref"
to it).


user@domain.invalid wrote:

>
> Sorry to drop this question..may be stupid one
>
> How can one get XSDAttributeUse for an attribute from
> attributedeclaration.
>
> best
>
> roy
>
> Ed Merks wrote:
>
>> Gary,
>>
>> Yes, that's exactly right. ;-)
>>
>>
>> Gary J wrote:
>>
>>> Thanks Ed,
>>>
>>> getAttributeContents vs getAttributeUses
>>>
>>> Am I correct that this is another example of the difference between
>>> the "Concrete" and "Abstract" representations of the schema?
>>>
>>> The Concrete representation is what's actually written in the schema
>>> file itself whereas Abstract is (sort of) the "expanded" version of
>>> the schema with all the inherited types, groups, refs, etc available.
>>>
>>> I'd use the Concrete model if I wanted to serialize (write) the
>>> schema and the Abstract to walk the schema elements, among other
>>> things.
>>>
>>> I think I'm actually starting to get a clue. That perhaps qualifies
>>> me a "cluebie" .
>>>
>>>
>>>
>>>
>>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>>> news:cgf9ov$ujg$1@eclipse.org...
>>> Gary,
>>>
>>> Yes, the contents will always be of type XSDAttributeUse, so there's no
>>> need for a instanceof check. Note that getAttributeContents returns
>>> the
>>> physically contained attribute declarations whereas getAttributeUses
>>> will get the inherited ones as well as the local ones just as
>>> getContent
>>> returns the physically contained content model (particle/simple type)
>>> whereas getContentType will return the inherited content model as well.
>>>
>>>
>>> Gary J wrote:
>>>
>>>
>>>
>>>> I think I found what I need. Here's some code I wrote to print out
>>>> attributes for an element. Correct me if I'm wrong.
>>>>
>>>> Starting with: ElementDeclaration element
>>>>
>>>> XSDTypeDefinition type = element.getTypeDefinition();
>>>>
>>>> if (type instanceof XSDComplexTypeDefinition)
>>>> {
>>>> EList list = ((XSDComplexTypeDefinition)
>>>> type).getAttributeContents();
>>>>
>>>> for (Iterator iter = list.iterator(); iter.hasNext();)
>>>> {
>>>> Object obj = iter.next();
>>>> if (obj instanceof XSDAttributeUse)
>>>> {
>>>> XSDAttributeUse a = (XSDAttributeUse) obj;
>>>> System.out.println(a.getAttributeDeclaration().getName());
>>>> }
>>>> }
>>>> }
>>>>
>>>> I'm not sure if the results of getAttributeContents() are always an
>>>> instance
>>>> of XSDAttributeUse so I check just in case.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>
Re: How to retrieve Attributes for a complex ElementDeclaration [message #590790 is a reply to message #51267] Tue, 24 August 2004 03:15 Go to previous message
Gary J is currently offline Gary J
Messages: 61
Registered: July 2009
Member
I think I found what I need. Here's some code I wrote to print out
attributes for an element. Correct me if I'm wrong.

Starting with: ElementDeclaration element

XSDTypeDefinition type = element.getTypeDefinition();

if (type instanceof XSDComplexTypeDefinition)
{
EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();

for (Iterator iter = list.iterator(); iter.hasNext();)
{
Object obj = iter.next();
if (obj instanceof XSDAttributeUse)
{
XSDAttributeUse a = (XSDAttributeUse) obj;
System.out.println(a.getAttributeDeclaration().getName());
}
}
}

I'm not sure if the results of getAttributeContents() are always an instance
of XSDAttributeUse so I check just in case.
Re: How to retrieve Attributes for a complex ElementDeclaration [message #590923 is a reply to message #51293] Tue, 24 August 2004 11:48 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Gary,

Yes, the contents will always be of type XSDAttributeUse, so there's no
need for a instanceof check. Note that getAttributeContents returns the
physically contained attribute declarations whereas getAttributeUses
will get the inherited ones as well as the local ones just as getContent
returns the physically contained content model (particle/simple type)
whereas getContentType will return the inherited content model as well.


Gary J wrote:

>I think I found what I need. Here's some code I wrote to print out
>attributes for an element. Correct me if I'm wrong.
>
>Starting with: ElementDeclaration element
>
> XSDTypeDefinition type = element.getTypeDefinition();
>
> if (type instanceof XSDComplexTypeDefinition)
> {
> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>
> for (Iterator iter = list.iterator(); iter.hasNext();)
> {
> Object obj = iter.next();
> if (obj instanceof XSDAttributeUse)
> {
> XSDAttributeUse a = (XSDAttributeUse) obj;
> System.out.println(a.getAttributeDeclaration().getName());
> }
> }
> }
>
>I'm not sure if the results of getAttributeContents() are always an instance
>of XSDAttributeUse so I check just in case.
>
>
>
>
Re: How to retrieve Attributes for a complex ElementDeclaration [message #590953 is a reply to message #51458] Tue, 24 August 2004 14:32 Go to previous message
Gary J is currently offline Gary J
Messages: 61
Registered: July 2009
Member
Thanks Ed,

getAttributeContents vs getAttributeUses

Am I correct that this is another example of the difference between the
"Concrete" and "Abstract" representations of the schema?

The Concrete representation is what's actually written in the schema file
itself whereas Abstract is (sort of) the "expanded" version of the schema
with all the inherited types, groups, refs, etc available.

I'd use the Concrete model if I wanted to serialize (write) the schema and
the Abstract to walk the schema elements, among other things.

I think I'm actually starting to get a clue. That perhaps qualifies me a
"cluebie" .




"Ed Merks" <merks@ca.ibm.com> wrote in message
news:cgf9ov$ujg$1@eclipse.org...
Gary,

Yes, the contents will always be of type XSDAttributeUse, so there's no
need for a instanceof check. Note that getAttributeContents returns the
physically contained attribute declarations whereas getAttributeUses
will get the inherited ones as well as the local ones just as getContent
returns the physically contained content model (particle/simple type)
whereas getContentType will return the inherited content model as well.


Gary J wrote:

>I think I found what I need. Here's some code I wrote to print out
>attributes for an element. Correct me if I'm wrong.
>
>Starting with: ElementDeclaration element
>
> XSDTypeDefinition type = element.getTypeDefinition();
>
> if (type instanceof XSDComplexTypeDefinition)
> {
> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>
> for (Iterator iter = list.iterator(); iter.hasNext();)
> {
> Object obj = iter.next();
> if (obj instanceof XSDAttributeUse)
> {
> XSDAttributeUse a = (XSDAttributeUse) obj;
> System.out.println(a.getAttributeDeclaration().getName());
> }
> }
> }
>
>I'm not sure if the results of getAttributeContents() are always an
>instance
>of XSDAttributeUse so I check just in case.
>
>
>
>
Re: How to retrieve Attributes for a complex ElementDeclaration [message #590966 is a reply to message #51512] Tue, 24 August 2004 14:37 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020405000909090205010801
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Gary,

Yes, that's exactly right. ;-)


Gary J wrote:

>Thanks Ed,
>
>getAttributeContents vs getAttributeUses
>
>Am I correct that this is another example of the difference between the
>"Concrete" and "Abstract" representations of the schema?
>
>The Concrete representation is what's actually written in the schema file
>itself whereas Abstract is (sort of) the "expanded" version of the schema
>with all the inherited types, groups, refs, etc available.
>
>I'd use the Concrete model if I wanted to serialize (write) the schema and
>the Abstract to walk the schema elements, among other things.
>
>I think I'm actually starting to get a clue. That perhaps qualifies me a
>"cluebie" .
>
>
>
>
>"Ed Merks" <merks@ca.ibm.com> wrote in message
>news:cgf9ov$ujg$1@eclipse.org...
>Gary,
>
>Yes, the contents will always be of type XSDAttributeUse, so there's no
>need for a instanceof check. Note that getAttributeContents returns the
>physically contained attribute declarations whereas getAttributeUses
>will get the inherited ones as well as the local ones just as getContent
>returns the physically contained content model (particle/simple type)
>whereas getContentType will return the inherited content model as well.
>
>
>Gary J wrote:
>
>
>
>>I think I found what I need. Here's some code I wrote to print out
>>attributes for an element. Correct me if I'm wrong.
>>
>>Starting with: ElementDeclaration element
>>
>>XSDTypeDefinition type = element.getTypeDefinition();
>>
>>if (type instanceof XSDComplexTypeDefinition)
>> {
>> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>>
>> for (Iterator iter = list.iterator(); iter.hasNext();)
>> {
>> Object obj = iter.next();
>> if (obj instanceof XSDAttributeUse)
>> {
>> XSDAttributeUse a = (XSDAttributeUse) obj;
>> System.out.println(a.getAttributeDeclaration().getName());
>> }
>> }
>> }
>>
>>I'm not sure if the results of getAttributeContents() are always an
>>instance
>>of XSDAttributeUse so I check just in case.
>>
>>
>>
>>
>>
>>
>
>
>
>


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

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Gary,<br>
<br>
Yes, that's exactly right. ;-)<br>
<br>
<br>
Gary J wrote:<br>
<blockquote cite="midcgfjbg$i5q$1@eclipse.org" type="cite">
<pre wrap="">Thanks Ed,

getAttributeContents vs getAttributeUses

Am I correct that this is another example of the difference between the
"Concrete" and "Abstract" representations of the schema?

The Concrete representation is what's actually written in the schema file
itself whereas Abstract is (sort of) the "expanded" version of the schema
with all the inherited types, groups, refs, etc available.

I'd use the Concrete model if I wanted to serialize (write) the schema and
the Abstract to walk the schema elements, among other things.

I think I'm actually starting to get a clue. That perhaps qualifies me a
"cluebie" .




"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:merks@ca.ibm.com">&lt;merks@ca.ibm.com&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:cgf9ov$ujg$1@eclipse.org">news:cgf9ov$ujg$1@eclipse.org</a>...
Gary,

Yes, the contents will always be of type XSDAttributeUse, so there's no
need for a instanceof check. Note that getAttributeContents returns the
physically contained attribute declarations whereas getAttributeUses
will get the inherited ones as well as the local ones just as getContent
returns the physically contained content model (particle/simple type)
whereas getContentType will return the inherited content model as well.


Gary J wrote:

</pre>
<blockquote type="cite">
<pre wrap="">I think I found what I need. Here's some code I wrote to print out
attributes for an element. Correct me if I'm wrong.

Starting with: ElementDeclaration element

XSDTypeDefinition type = element.getTypeDefinition();

if (type instanceof XSDComplexTypeDefinition)
{
EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();

for (Iterator iter = list.iterator(); iter.hasNext();)
{
Object obj = iter.next();
if (obj instanceof XSDAttributeUse)
{
XSDAttributeUse a = (XSDAttributeUse) obj;
System.out.println(a.getAttributeDeclaration().getName());
}
}
}

I'm not sure if the results of getAttributeContents() are always an
instance
of XSDAttributeUse so I check just in case.




</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
<br>
</body>
</html>

--------------020405000909090205010801--
attribute use from declaration [message #592228 is a reply to message #51538] Wed, 27 October 2004 06:49 Go to previous message
user is currently offline user
Messages: 296
Registered: July 2009
Senior Member
Sorry to drop this question..may be stupid one

How can one get XSDAttributeUse for an attribute from attributedeclaration.

best

roy

Ed Merks wrote:
> Gary,
>
> Yes, that's exactly right. ;-)
>
>
> Gary J wrote:
>
>>Thanks Ed,
>>
>>getAttributeContents vs getAttributeUses
>>
>>Am I correct that this is another example of the difference between the
>>"Concrete" and "Abstract" representations of the schema?
>>
>>The Concrete representation is what's actually written in the schema file
>>itself whereas Abstract is (sort of) the "expanded" version of the schema
>>with all the inherited types, groups, refs, etc available.
>>
>>I'd use the Concrete model if I wanted to serialize (write) the schema and
>>the Abstract to walk the schema elements, among other things.
>>
>>I think I'm actually starting to get a clue. That perhaps qualifies me a
>>"cluebie" .
>>
>>
>>
>>
>>"Ed Merks" <merks@ca.ibm.com> wrote in message
>>news:cgf9ov$ujg$1@eclipse.org...
>>Gary,
>>
>>Yes, the contents will always be of type XSDAttributeUse, so there's no
>>need for a instanceof check. Note that getAttributeContents returns the
>>physically contained attribute declarations whereas getAttributeUses
>>will get the inherited ones as well as the local ones just as getContent
>>returns the physically contained content model (particle/simple type)
>>whereas getContentType will return the inherited content model as well.
>>
>>
>>Gary J wrote:
>>
>>
>>
>>>I think I found what I need. Here's some code I wrote to print out
>>>attributes for an element. Correct me if I'm wrong.
>>>
>>>Starting with: ElementDeclaration element
>>>
>>>XSDTypeDefinition type = element.getTypeDefinition();
>>>
>>>if (type instanceof XSDComplexTypeDefinition)
>>> {
>>> EList list = ((XSDComplexTypeDefinition) type).getAttributeContents();
>>>
>>> for (Iterator iter = list.iterator(); iter.hasNext();)
>>> {
>>> Object obj = iter.next();
>>> if (obj instanceof XSDAttributeUse)
>>> {
>>> XSDAttributeUse a = (XSDAttributeUse) obj;
>>> System.out.println(a.getAttributeDeclaration().getName());
>>> }
>>> }
>>> }
>>>
>>>I'm not sure if the results of getAttributeContents() are always an
>>>instance
>>>of XSDAttributeUse so I check just in case.
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>
Re: attribute use from declaration [message #592249 is a reply to message #54280] Wed, 27 October 2004 17:00 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Roy,

If the attribute use is not the container
(XSDConcreteComponent.getContainer()) of the attribute declaration, then
there isn't a way since there can be arbitrarily many attributes uses
that share a particular attribute declaration (because they have "ref"
to it).


user@domain.invalid wrote:

>
> Sorry to drop this question..may be stupid one
>
> How can one get XSDAttributeUse for an attribute from
> attributedeclaration.
>
> best
>
> roy
>
> Ed Merks wrote:
>
>> Gary,
>>
>> Yes, that's exactly right. ;-)
>>
>>
>> Gary J wrote:
>>
>>> Thanks Ed,
>>>
>>> getAttributeContents vs getAttributeUses
>>>
>>> Am I correct that this is another example of the difference between
>>> the "Concrete" and "Abstract" representations of the schema?
>>>
>>> The Concrete representation is what's actually written in the schema
>>> file itself whereas Abstract is (sort of) the "expanded" version of
>>> the schema with all the inherited types, groups, refs, etc available.
>>>
>>> I'd use the Concrete model if I wanted to serialize (write) the
>>> schema and the Abstract to walk the schema elements, among other
>>> things.
>>>
>>> I think I'm actually starting to get a clue. That perhaps qualifies
>>> me a "cluebie" .
>>>
>>>
>>>
>>>
>>> "Ed Merks" <merks@ca.ibm.com> wrote in message
>>> news:cgf9ov$ujg$1@eclipse.org...
>>> Gary,
>>>
>>> Yes, the contents will always be of type XSDAttributeUse, so there's no
>>> need for a instanceof check. Note that getAttributeContents returns
>>> the
>>> physically contained attribute declarations whereas getAttributeUses
>>> will get the inherited ones as well as the local ones just as
>>> getContent
>>> returns the physically contained content model (particle/simple type)
>>> whereas getContentType will return the inherited content model as well.
>>>
>>>
>>> Gary J wrote:
>>>
>>>
>>>
>>>> I think I found what I need. Here's some code I wrote to print out
>>>> attributes for an element. Correct me if I'm wrong.
>>>>
>>>> Starting with: ElementDeclaration element
>>>>
>>>> XSDTypeDefinition type = element.getTypeDefinition();
>>>>
>>>> if (type instanceof XSDComplexTypeDefinition)
>>>> {
>>>> EList list = ((XSDComplexTypeDefinition)
>>>> type).getAttributeContents();
>>>>
>>>> for (Iterator iter = list.iterator(); iter.hasNext();)
>>>> {
>>>> Object obj = iter.next();
>>>> if (obj instanceof XSDAttributeUse)
>>>> {
>>>> XSDAttributeUse a = (XSDAttributeUse) obj;
>>>> System.out.println(a.getAttributeDeclaration().getName());
>>>> }
>>>> }
>>>> }
>>>>
>>>> I'm not sure if the results of getAttributeContents() are always an
>>>> instance
>>>> of XSDAttributeUse so I check just in case.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>
Previous Topic:XSD and WTP relationships
Next Topic:EMF-based DOM
Goto Forum:
  


Current Time: Sat Oct 25 08:58:31 GMT 2014

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

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