You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Saha, Sanjeev" <SS...@asce.org> on 2004/05/19 17:04:53 UTC

RE: Retrieving QName from newInstance()

Eric,

Apparently, I was trying to replicate, in parts, the features already
provided by the SchemaTypeLoader w.r.t loading the compiled schema types
for any given xml.

Instead of using the dynamic loading from the classpath, I was trying to
create a cache of compiled schema types and hence the requirement to
retrieve the QName of the global element.

Needless to say, the dynamic loading works great!!!

-Sanjeev

-----Original Message-----
From: Eric Vasilik [mailto:ericvas@bea.com] 
Sent: Tuesday, May 18, 2004 1:30 PM
To: xmlbeans-user@xml.apache.org
Subject: RE: Retrieving QName from newInstance()

You should not be getting null.  Does the global PurchaseOrder element
reference a global type, or does it locally define an anonymous complex
type?  If the former, then you will want to, assume the referenced type
is named PurchaseOrderType, use:

    PurchaseOrderType.type.getName()

In reference to the string:

    "D=purchase-order@http://openuri.org/easypo",

this is name XmlBeans synthesizes to uniquely identity a SchemType,
regardless of whether or not it has a name.

It is still not clear to me what you are trying to do.  What do you want
to put into your cache?  Do want to put a number of instances as values
in your cache, all keyed off of a QName?  If so, what kind of instances?
Instance of global elements and global types?

- Eric
    

> -----Original Message-----
> From: Saha, Sanjeev [mailto:SSaha@asce.org]
> Sent: Tuesday, May 18, 2004 10:18 AM
> To: xmlbeans-user@xml.apache.org
> Subject: RE: Retrieving QName from newInstance()
> 
> Hmmm..
> 
> PurchaseOrderDocument.PurchaseOrder.type.getName() seems to be
returning
> 'null'
> 
> Considering that identifying the global element like PurchaseOrder
might
> pose some constraints in writing a generic api as it might get
difficult
> to identify the root element at runtime, I did notice that once an
> instance is created, say poDoc, poDoc.schemaType() returns
> "D=purchase-order@http://openuri.org/easypo"
> 
> It would be easy to tokenize this value and convert it into
> {http://openuri.org/easypo}purchase-order.
> 
> Would this be a safe and acceptable approach?
> 
> -Sanjeev
> 
> -----Original Message-----
> From: Eric Vasilik [mailto:ericvas@bea.com]
> Sent: Tuesday, May 18, 2004 12:50 PM
> To: xmlbeans-user@xml.apache.org
> Subject: RE: Retrieving QName from newInstance()
> 
> Ok.  Then try:
> 
>     PurchaseOrderDocument.PurchaseOrder.type.getName()
> 
> This will return the QName of the global PurchaseOrder element.  No
need
> to create an instance!
> 
> - Eric
> 
> > -----Original Message-----
> > From: Saha, Sanjeev [mailto:SSaha@asce.org]
> > Sent: Tuesday, May 18, 2004 9:44 AM
> > To: xmlbeans-user@xml.apache.org
> > Subject: RE: Retrieving QName from newInstance()
> >
> > To shed more light, if you consider the sample easypo.xsd which has
> > targetNamespace=http://openuri.org/easypo, the intent is to retrieve
> > {http://openuri.org/easypo}purchase-order, in order to store it in
the
> > HashMap.
> >
> > I do agree that unless I parse an xml using
> > PurchaseOrderDocument.Factory.parse(Object) there will not be any
> > content as the newInstance() creates a holder, but is there any way
to
> > get this information from the global schema element holder
considering
> > that it was available in the xsd? Please keep in mind that I am
trying
> > to get  "{http://openuri.org/easypo}purchase-order" that was
provided
> in
> > easypo.xsd without parsing an xml.
> >
> > The reason this information is required, other than the fact that it
> is
> > used as a key into the HashMap is that once the
PurchaseOrderDocument
> > class is located in the class path, it is passed along to an
> > add(XmlObject) api that tries to build a key from the passed
> XmlObject.
> > I can build the key by making the namespace as a constant but wanted
> to
> > refrain from doing that for obvious reason leading to hard coding in
> the
> > java class.
> >
> > -Sanjeev
> >
> > -----Original Message-----
> > From: Eric Vasilik [mailto:ericvas@bea.com]
> > Sent: Tuesday, May 18, 2004 12:26 PM
> > To: xmlbeans-user@xml.apache.org
> > Subject: RE: Retrieving QName from newInstance()
> >
> > The getName method on XmlCursor usually returns the name of an
element
> > or attribute.  I'm not sure what you mean by wanting the QName of
the
> > default schema XmlObject.
> >
> > XmlObjects have a type member which is the SchemaType of which they
> are
> > an instance.  Some SchemaTypes have names, usually the global name
> from
> > the schema source file, combined with the target namespace.  Many
> > SchemaTypes have no names because they are anonymous.  In your case,
> > PurchaseOrderDocument.type has no name because DocumentTypes are
> > synthesized by our schema compiler to represent a holder for global
> > schema elements.  Also, creating an instance of this type (poDoc)
> > creates such a holder, but initially, there is no content, thus the
> > <xml-fragment/> when you save it out.
> >
> > - Eric
> >
> > > -----Original Message-----
> > > From: Saha, Sanjeev [mailto:SSaha@asce.org]
> > > Sent: Tuesday, May 18, 2004 9:19 AM
> > > To: xmlbeans-user@xml.apache.org
> > > Subject: Retrieving QName from newInstance()
> > >
> > > Requirement
> > > ===========
> > > To create an XmlObject pool represented in the form of a HashMap
> where
> > > the key is the QName and the value is an instance/reference to the
> > > schema XmlObject.
> > >
> > > Intention
> > > =========
> > > Given an incoming xml, to simplify the Schema XmlObject look-up
> based
> > on
> > > the QName of the xml.
> > >
> > > Approach
> > > ========
> > > Trying to create an instance using, for example, poDoc =
> > > PurchaseOrderDocument.Factory.newInstance(). Although the instance
> is
> > > created, a quick System.out reveals that the contents are
> > > <xml-fragment></xml-fragment>, which is fine.
> > >
> > > However, attempts to use an XmlCursor to retrieve the QName of the
> > > default schema XmlObject returns null:
> > > XmlCursor xc = poDoc.newCursor();
> > > xc.toStartDoc();
> > > xc.toFirstChild() or xc.toFirstContentToken();
> > > xc.getName() returns 'null'
> > >
> > > Is there a different approach that needs to be followed to achieve
> the
> > > required result?
> > >
> > > -Sanjeev
> >
> >
> > -
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> > Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
> 
> 
> -
---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/
> 
> 
> -
---------------------------------------------------------------------
> To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
> Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/


- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/