[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-user
Subject: RE: Getting Annotations
From: "Radu Preotiuc-Pietro" <radu.preotiuc-pietro () oracle ! com>
Date: 2008-10-01 3:05:14
Message-ID: 20080930200514015.00000002168 () RADUP02
[Download RAW message or body]
Well, what you are missing is the fact that athlete.schemaType().getAnnnotation() is \
getting the <annotation> on the "data:athlete" type, not the "athlete" element (The \
type can just as well have its own annotation).
Now, what you are probably wondering is how to get to the element associated with \
your XmlObject. But the thing is that XmlObjects are instances of types, not of \
elements. The only way to get the element is to get the element's name (via \
athlete.newCursor().getName()), then get the parent's type content model \
(athleteParent.schemaType().getContentModel()) and then traverse the content model. I \
know it looks more complicated than necessary, but because you can have multiple \
elements with different names but the same type, as well as multiple elements with \
the same name but different annotations, all in the same "parent" type , it is \
necessary to have a bit of logic to specify which element exactly you are looking \
for.
Radu
________________________________
From: Eric Murphy [mailto:ericmurphy@shaw.ca]
Sent: Friday, September 26, 2008 10:34 PM
To: user@xmlbeans.apache.org
Subject: Getting Annotations
I expect to find an annotation for my athlete element but the value is "null". Here \
is the element declaration:
<element name="athlete" type="data:athlete" maxOccurs="unbounded" minOccurs="1">
<annotation>
<documentation>
An athlete must have a valid person description and a sport list containing at \
least one sport.
</documentation>
</annotation>
</element>
Here is my code to get the annotation:
SchemaAnnotation annotation = athlete.schemaType().getAnnotation();
Seems simple enough. What am I missing?
Thanks
Eric
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" xmlns:o =
"urn:schemas-microsoft-com:office:office" xmlns:w =
"urn:schemas-microsoft-com:office:word"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3395" name=GENERATOR>
<STYLE>@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 90.0pt 72.0pt 90.0pt; }
P.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: Arial
}
LI.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: Arial
}
DIV.MsoNormal {
FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: Arial
}
A:link {
COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
COLOR: windowtext; FONT-FAMILY: Arial; mso-style-type: personal-compose
}
DIV.Section1 {
page: Section1
}
</STYLE>
</HEAD>
<BODY lang=EN-CA vLink=purple link=blue>
<DIV dir=ltr align=left><SPAN class=093444802-01102008><FONT face=Arial
color=#0000ff size=2>Well, what you are missing is the fact that
athlete.schemaType().getAnnnotation() is getting the <annotation> on the
"data:athlete" type, not the "athlete" element (The type can just as well have
its own annotation).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=093444802-01102008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=093444802-01102008><FONT face=Arial
color=#0000ff size=2>Now, what you are probably wondering is how to
get to the element associated with your XmlObject. But the thing is
that XmlObjects are instances of types, not of elements. The only way to
get the element is to get the element's name (via
athlete.newCursor().getName()), then get the parent's type content
model (athleteParent.schemaType().getContentModel()) and then traverse the
content model. I know it looks more complicated than necessary, but because you
can have multiple elements with different names but the same type, as well as
multiple elements with the same name but different annotations, all in the
same "parent" type , it is necessary to have a bit of logic to
specify which element exactly you are looking for.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=093444802-01102008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=093444802-01102008><FONT face=Arial
color=#0000ff size=2>Radu</FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; \
MARGIN-RIGHT: 0px"> <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Eric Murphy [mailto:ericmurphy@shaw.ca]
<BR><B>Sent:</B> Friday, September 26, 2008 10:34 PM<BR><B>To:</B>
user@xmlbeans.apache.org<BR><B>Subject:</B> Getting
Annotations<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV class=Section1>
<P class=MsoNormal><FONT face=Arial size=2><SPAN lang=EN-US
style="FONT-SIZE: 10pt">I expect to find an annotation for my athlete element
but the value is “null”. Here is the element
declaration:<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face=Arial size=2><SPAN lang=EN-US
style="FONT-SIZE: 10pt"><o:p> </o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"><element name=<I><SPAN
style="FONT-STYLE: italic">"athlete" </SPAN></I>type=<I><SPAN
style="FONT-STYLE: italic">"data:athlete" </SPAN></I>maxOccurs=<I><SPAN
style="FONT-STYLE: italic">"unbounded" </SPAN></I>minOccurs=<I><SPAN
style="FONT-STYLE: italic">"1"</SPAN></I>><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<annotation><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
<documentation><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
An athlete must have a valid person description and a sport list containing at
least one sport.<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
</documentation><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">
</annotation><o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'"></element><o:p></o:p></SPAN></FONT></P> <P class=MsoNormal><FONT \
face="Courier New" color=teal size=2><SPAN style="FONT-SIZE: 10pt; COLOR: teal; \
FONT-FAMILY: 'Courier New'"><o:p> </o:p></SPAN></FONT></P> <P \
class=MsoNormal><FONT face="Courier New" size=2><SPAN style="FONT-SIZE: 10pt; \
FONT-FAMILY: 'Courier New'">Here is my code to get the \
annotation:<o:p></o:p></SPAN></FONT></P> <P class=MsoNormal><FONT face="Courier New" \
size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'"><o:p> </o:p></SPAN></FONT></P> <P class=MsoNormal><FONT face="Courier \
New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'">SchemaAnnotation annotation =
athlete.schemaType().getAnnotation();<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'"><o:p> </o:p></SPAN></FONT></P> <P class=MsoNormal><FONT face="Courier \
New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'">Seems simple \
enough. What am I missing?<o:p></o:p></SPAN></FONT></P>
<P class=MsoNormal><FONT face="Courier New" size=2><SPAN
style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'"><o:p> </o:p></SPAN></FONT></P> <P class=MsoNormal><FONT face="Courier \
New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'">Thanks<o:p></o:p></SPAN></FONT></P> <P class=MsoNormal><FONT face="Courier \
New" size=2><SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier \
New'">Eric<o:p></o:p></SPAN></FONT></P></DIV></BLOCKQUOTE></BODY></HTML>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic