xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Radu Preotiuc-Pietro" <ra...@bea.com>
Subject RE: How do I extract the Non-Native Attribute information from the compiled SchemaTypeSystem?
Date Thu, 18 Nov 2004 23:07:54 GMT
The difference is that you can have:
<xs:element name=3D"foo-element" my:attrib=3D"value1">
  <xs:complexType>
    ...
  </xs:complexType>
</xs:element>
=20
or
=20
<xs:element name=3D"foo-element">
  <xs:complexType my:attrib=3D"value1">
    ...
  </xs:complexType>
</xs:element>
=20
Your code will work with the second case, in order to capture the first =
case, you need to do
SchemaAnnotation ann =3D element.getAnnotation();
right after getting the element.

-----Original Message-----
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 2:37 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from =
the compiled SchemaTypeSystem?


Here is the code snippet that I was using to print the annotation =
attribute info using the SchemaType.getAnnotation()=20
=20
public class FooSample {
=20
 public static void main(String[] args) {
 =20
   QName qName =3D new QName(" http://foo.org/2004","foo-element =
<http://foo.org/2004> ");
 =20
  SchemaTypeLoader loader =3D XmlBeans.getContextTypeLoader();=20
  FooSample fooSample =3D new   FooSample();
 =20
   SchemaGlobalElement element =3D loader.findElement(qName);
   type =3D element.getType();
  fooSample.printTypeInfo(type);
  fooSample.printAnnotationAttribs(type);
 =20
 }
=20
 public  void printTypeInfo(SchemaType type)
 {
  if (type.isSimpleType()){
   printAnnotationAttribs(type);
  }
  else
  {
   printAnnotationAttribs(type);
   SchemaProperty[] props =3D type.getElementProperties();
   for (int index=3D0; index<props.length; index++)
   {
    printTypeInfo(props[index].getType());
   }
  }
 }
=20
 public void printAnnotationAttribs(SchemaType type)
 {
  SchemaAnnotation annotation =3D type.getAnnotation();
  if (annotation =3D=3D null)
  {
   System.out.println("Annotation is null");
   return;
  }
  SchemaAnnotation.Attribute[] myAttribs =3D annotation.getAttributes();
  if ((myAttribs =3D=3D null)||(myAttribs.length > 0))
  {
   System.out.println("Annotation Attributes are not available");
   return;
  }
  for (int index=3D0; index<myAttribs.length;index++ )
  {
   String localPart =3D  myAttribs[index].getName().getLocalPart() ;
   System.out.println("My Annotation Attribute Name =3D " +localPart+ "; =
Value =3D " + myAttribs[index].getValue());
  }
 }

  _____ =20

From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]=20
Sent: Thursday, November 18, 2004 5:27 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from =
the compiled SchemaTypeSystem?


yes, that is exactly what I want to do. I need to know if a given =
SchemaComponent has any special attribute or not.=20
I need this info not only for the global elements/types but also for the =
inner/local elements and attributes.
=20
I was not sure how to loop inside the SchemaGloablElement' to find the =
annotation information for the local elements f1 and f2.
=20
I was trying to get the type of the global element and use the =
getAnnotation() on the SchemaType interface. But it is returning any =
annotation attributes.
=20
What is the difference between getAnnotation() on the Global components =
vs. their schema types?
=20
thanks
Bharat
=20
=20
=20

=20
  _____ =20

From: Radu Preotiuc-Pietro [mailto:radup@bea.com]=20
Sent: Thursday, November 18, 2004 4:34 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from =
the compiled SchemaTypeSystem?


Most of the Schema* objects also implement the SchemaAnnotated =
interface, giving you access to the .getAnnotation() method.
You can certainly loop over all top-level elements (using =
sts.globalElements()), top-level types (using sts.globalTypes()) etc. =
and get the annotation for each one of them.
If you are just interested in the annotations though, you can very well =
use an XmlCursor and get all the namespace-qualified attributes in your =
Schema document. But I thought you were interested in the relashionship =
between the SchemaComponent and the annotation on it, like "oh, I have a =
global element named foo and I have one of my special attributes on it, =
therefore I should do something special", rather than just list your =
attributes.
=20
Radu

-----Original Message-----
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 1:07 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from =
the compiled SchemaTypeSystem?


thanks Radu. That helps, but at the same time I am not quite understood =
how to get the annotation attributes for rest of the elements or schema =
components.
=20
As almost all XSDL elements are allowed to have the annotation elements, =
is there an easy way to loop through each XSDL element to find this =
info.
=20
=20
=20
=20
=20
  _____ =20

From: Radu Preotiuc-Pietro [mailto:radup@bea.com]=20
Sent: Thursday, November 18, 2004 3:07 PM
To: dev@xmlbeans.apache.org
Subject: RE: How do I extract the Non-Native Attribute information from =
the compiled SchemaTypeSystem?


By "non-native attributes" you mean XSD annotations.
In order to get those, do:
SchemaGlobalElement foo =3D sts.findElement(new QName("  =
<http://foo.org/2004> http://foo.org/2004","foo-element"));
SchemaAnnotation.Attribute[] atts =3D =
foo.getAnnotation().getAttributes();
=20
Radu

-----Original Message-----
From: Bharat K. Veeragandham [mailto:bharat@iservicesusa.com]
Sent: Thursday, November 18, 2004 9:00 AM
To: xmlbeans-dev@xml.apache.org
Subject: How do I extract the Non-Native Attribute information from the =
compiled SchemaTypeSystem?



Hi,=20

Can some one help with the XSDL non-native attributes?=20

I would like to extend the  standard XSDL with my own non-native =
attributes as shown in the following schema.=20
XmlBeans compiles the schema w/o any errors but I couldn't find a way to =
get the information about the non-native attributes from the compiled =
type system.

I am using the latest xmlbeans-V2 code.=20

<xs:schema=20
   xmlns:xs=3D" http://www.w3.org/2001/XMLSchema"=20
   xmlns:foo=3D" http://foo.org/2004"=20
   xmlns:my=3D" http://foo.org/myExtension"=20
   targetNamespace=3D" http://foo.org/2004"=20
   elementFormDefault=3D"qualified">=20

  <xs:element name=3D"foo-element" my:attrib1=3D"myValue1">=20
    <xs:complexType>=20
      <xs:sequence>=20
        <xs:element name=3D"f1" type=3D"xs:string" =
my:attrib2=3D"myValue2"/>=20
        <xs:element name=3D"f2" type=3D"xs:string" =
my:attrib2=3D"myValue3"/>=20
        </xs:sequence>=20
    </xs:complexType>=20
  </xs:element>=20
</xs:schema>=20


Thanks for your help

-Bharat=20


Mime
View raw message