Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Proper way to get the default value for an attribute
Proper way to get the default value for an attribute [message #73071] Fri, 28 September 2007 14:27 Go to next message
Richard Gregory is currently offline Richard GregoryFriend
Messages: 13
Registered: July 2009
Junior Member
Hi,

I have this code to get the default value that works fine for an
XSDElementDeclaration:

XSDElementDeclaration.getLexicalValue();

However, when I call get XSDAttributeDeclaration.getLexicalValue(), it
always returns null, for example with this XSD:

<xsd:complexType name="HasDefault">
<xsd:sequence>
<xsd:element minOccurs="0" name="field1" type="xsd:string"
default="some default value" />
</xsd:sequence>
<xsd:attribute name="attr" type="xsd:int" default="123"/>
</xsd:complexType>

I see from introspecting the XSDAttributeDeclaration at runtime that the
default value is in XSDAttributeDeclaration.eContainer.lexicalValue and
in .value, where eContainer is an XSDAttributeUse.

So I can write code to get it from there, but is that the right way? I
would expect a more direct way.

Thanks,

Rich
Re: Proper way to get the default value for an attribute [message #73089 is a reply to message #73071] Fri, 28 September 2007 15:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Rich,

It's kind of nasty how this works. A global attribute attribute
declaration can directly have a default and then a reference to that
attribute can have a different default and the specification defines
that the attribute use carries the default (which is different for the
element case were the element always carries the default, not the
particle). So you need to be pretty careful about keeping track of the
actual attribute use because once you've resolved to a global attribute
declaration whose container is the XSDSchema, the default that applies
there may not be the right one. So as a general rule of thumb, it's
best to keep your hands on the attribute use, otherwise you'll need to
work your way back to it via the eContainer()/getContainer() method (and
this isn't possible if you've gone so far as to resolve the attribute
reference to the global attribute)...


Richard Gregory wrote:
> Hi,
>
> I have this code to get the default value that works fine for an
> XSDElementDeclaration:
>
> XSDElementDeclaration.getLexicalValue();
>
> However, when I call get XSDAttributeDeclaration.getLexicalValue(), it
> always returns null, for example with this XSD:
>
> <xsd:complexType name="HasDefault">
> <xsd:sequence>
> <xsd:element minOccurs="0" name="field1" type="xsd:string"
> default="some default value" />
> </xsd:sequence>
> <xsd:attribute name="attr" type="xsd:int" default="123"/>
> </xsd:complexType>
>
> I see from introspecting the XSDAttributeDeclaration at runtime that
> the default value is in
> XSDAttributeDeclaration.eContainer.lexicalValue and in .value, where
> eContainer is an XSDAttributeUse.
>
> So I can write code to get it from there, but is that the right way? I
> would expect a more direct way.
>
> Thanks,
>
> Rich
Re: Proper way to get the default value for an attribute [message #73106 is a reply to message #73089] Sat, 29 September 2007 03:48 Go to previous message
Richard Gregory is currently offline Richard GregoryFriend
Messages: 13
Registered: July 2009
Junior Member
Thanks Ed! I see where I was going wrong.

Ed Merks wrote:
> Rich,
>
> It's kind of nasty how this works. A global attribute attribute
> declaration can directly have a default and then a reference to that
> attribute can have a different default and the specification defines
> that the attribute use carries the default (which is different for the
> element case were the element always carries the default, not the
> particle). So you need to be pretty careful about keeping track of the
> actual attribute use because once you've resolved to a global attribute
> declaration whose container is the XSDSchema, the default that applies
> there may not be the right one. So as a general rule of thumb, it's
> best to keep your hands on the attribute use, otherwise you'll need to
> work your way back to it via the eContainer()/getContainer() method (and
> this isn't possible if you've gone so far as to resolve the attribute
> reference to the global attribute)...
>
>
> Richard Gregory wrote:
>> Hi,
>>
>> I have this code to get the default value that works fine for an
>> XSDElementDeclaration:
>>
>> XSDElementDeclaration.getLexicalValue();
>>
>> However, when I call get XSDAttributeDeclaration.getLexicalValue(), it
>> always returns null, for example with this XSD:
>>
>> <xsd:complexType name="HasDefault">
>> <xsd:sequence>
>> <xsd:element minOccurs="0" name="field1" type="xsd:string"
>> default="some default value" />
>> </xsd:sequence>
>> <xsd:attribute name="attr" type="xsd:int" default="123"/>
>> </xsd:complexType>
>>
>> I see from introspecting the XSDAttributeDeclaration at runtime that
>> the default value is in
>> XSDAttributeDeclaration.eContainer.lexicalValue and in .value, where
>> eContainer is an XSDAttributeUse.
>>
>> So I can write code to get it from there, but is that the right way? I
>> would expect a more direct way.
>>
>> Thanks,
>>
>> Rich
Re: Proper way to get the default value for an attribute [message #602639 is a reply to message #73071] Fri, 28 September 2007 15:26 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26287
Registered: July 2009
Senior Member
Rich,

It's kind of nasty how this works. A global attribute attribute
declaration can directly have a default and then a reference to that
attribute can have a different default and the specification defines
that the attribute use carries the default (which is different for the
element case were the element always carries the default, not the
particle). So you need to be pretty careful about keeping track of the
actual attribute use because once you've resolved to a global attribute
declaration whose container is the XSDSchema, the default that applies
there may not be the right one. So as a general rule of thumb, it's
best to keep your hands on the attribute use, otherwise you'll need to
work your way back to it via the eContainer()/getContainer() method (and
this isn't possible if you've gone so far as to resolve the attribute
reference to the global attribute)...


Richard Gregory wrote:
> Hi,
>
> I have this code to get the default value that works fine for an
> XSDElementDeclaration:
>
> XSDElementDeclaration.getLexicalValue();
>
> However, when I call get XSDAttributeDeclaration.getLexicalValue(), it
> always returns null, for example with this XSD:
>
> <xsd:complexType name="HasDefault">
> <xsd:sequence>
> <xsd:element minOccurs="0" name="field1" type="xsd:string"
> default="some default value" />
> </xsd:sequence>
> <xsd:attribute name="attr" type="xsd:int" default="123"/>
> </xsd:complexType>
>
> I see from introspecting the XSDAttributeDeclaration at runtime that
> the default value is in
> XSDAttributeDeclaration.eContainer.lexicalValue and in .value, where
> eContainer is an XSDAttributeUse.
>
> So I can write code to get it from there, but is that the right way? I
> would expect a more direct way.
>
> Thanks,
>
> Rich
Re: Proper way to get the default value for an attribute [message #602645 is a reply to message #73089] Sat, 29 September 2007 03:48 Go to previous message
Richard Gregory is currently offline Richard GregoryFriend
Messages: 13
Registered: July 2009
Junior Member
Thanks Ed! I see where I was going wrong.

Ed Merks wrote:
> Rich,
>
> It's kind of nasty how this works. A global attribute attribute
> declaration can directly have a default and then a reference to that
> attribute can have a different default and the specification defines
> that the attribute use carries the default (which is different for the
> element case were the element always carries the default, not the
> particle). So you need to be pretty careful about keeping track of the
> actual attribute use because once you've resolved to a global attribute
> declaration whose container is the XSDSchema, the default that applies
> there may not be the right one. So as a general rule of thumb, it's
> best to keep your hands on the attribute use, otherwise you'll need to
> work your way back to it via the eContainer()/getContainer() method (and
> this isn't possible if you've gone so far as to resolve the attribute
> reference to the global attribute)...
>
>
> Richard Gregory wrote:
>> Hi,
>>
>> I have this code to get the default value that works fine for an
>> XSDElementDeclaration:
>>
>> XSDElementDeclaration.getLexicalValue();
>>
>> However, when I call get XSDAttributeDeclaration.getLexicalValue(), it
>> always returns null, for example with this XSD:
>>
>> <xsd:complexType name="HasDefault">
>> <xsd:sequence>
>> <xsd:element minOccurs="0" name="field1" type="xsd:string"
>> default="some default value" />
>> </xsd:sequence>
>> <xsd:attribute name="attr" type="xsd:int" default="123"/>
>> </xsd:complexType>
>>
>> I see from introspecting the XSDAttributeDeclaration at runtime that
>> the default value is in
>> XSDAttributeDeclaration.eContainer.lexicalValue and in .value, where
>> eContainer is an XSDAttributeUse.
>>
>> So I can write code to get it from there, but is that the right way? I
>> would expect a more direct way.
>>
>> Thanks,
>>
>> Rich
Previous Topic:Proper way to get the default value for an attribute
Next Topic:Eclipse : Write XML using XSD
Goto Forum:
  


Current Time: Sun Dec 21 15:58:16 GMT 2014

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

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