You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Wm.A.Stafford" <st...@marine.rutgers.edu> on 2009/01/08 23:00:13 UTC

Novice XmlBeans user question

I'm a novice user of XmlBeans.  I've used it successfully to parse 
several simple schemas but when I moved on to a more complicated schema 
I quickly came to a screeching halt.

Here is a segment of the schema I am working with:

<xsd:element name="metadata" type="metadataResultType">
    <xsd:annotation>
        <xsd:documentation>Global element to validate external metadata 
XMLfiles.</xsd:documentation>
    </xsd:annotation>
</xsd:element>
<xsd:complexType name="metadataResultType">
    <xsd:annotation>
        <xsd:documentation>Format of metadata operation 
result.</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element ref="dc:title">
            <xsd:annotation>
                <xsd:documentation>The name of this 
service</xsd:documentation>
            </xsd:annotation>
        </xsd:element>
        <xsd:element ref="dc:type">
            <xsd:annotation>
                <xsd:documentation>The nature or genre of the 
content</xsd:documentation>
            </xsd:annotation>
        </xsd:element>
           
        ... lots more elements
           
    </xsd:sequence>
</xsd:complexType>

Here is a segment of Java that XMLBeans generated.

/**
 * An XML metadataResultType(@http://rs.tdwg.org/tapir/1.0).
 *
 * This is a complex type.
 */
public interface MetadataResultType extends org.apache.xmlbeans.XmlObject
{
    public static final org.apache.xmlbeans.SchemaType type = 
(org.apache.xmlbeans.SchemaType)
        
org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(MetadataResultType.class.getClassLoader(), 
"schemaorg_apache_xmlbeans.system.sC4F7BF7BC2573C292B659C414C97BA9A").resolveHandle("metadataresulttype5083type");
   
    /**
     * Gets the "title" element
     */
    org.purl.dc.elements.x11.SimpleLiteral getTitle();
   

Here is a segment of java to extract the title from the server response. 
   
MetadataResultType doc = MetadataResultType.Factory.parse(new URL( 
server_url  ));
System.out.println("title=" + doc.getTitle() );
System.out.println("doc=" + doc.toString()) ;

This is the output of the code fragment. 

title=null

doc=<response xsi:schemaLocation="http://rs.tdwg.org/tapir/1.0 
http://rs.tdwg.org/tapir/1.0/schema/tapir.xsd" 
xmlns="http://rs.tdwg.org/tapir/1.0" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:dct="http://purl.org/dc/terms/" 
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" 
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <header>.. contents removed...</header>
  <metadata xml:lang="en">
    <dc:title xml:lang="en">Photo-identification Library</dc:title>
    <dc:type>http://purl.org/dc/dcmitype/Service</dc:type>
   
    ... lots more elements removed
 </metadata>
</response>

I would like to get the title, type and ... lots more elements from the 
response.  My first attempt,
calling getTitle(), seemed not only the obvious but the only choice. 

How to I get at title and the rest of the metadata sequence and why does 
getTitle() return null?

Thanks for any help or advice,
-=beeky
           

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by Jacob Danner <ja...@gmail.com>.
Okay, thats kind of what I thought. Check the XML you are getting back
from the serverURL. My guess is it won't match the document you are
trying to parse it to.


On Fri, Jan 9, 2009 at 10:39 AM, Wm.A.Stafford
<st...@marine.rutgers.edu> wrote:
> jacob,
>
> This is the exception that is thrown:
>
> rg.apache.xmlbeans.XmlException: Element
> response@http://rs.tdwg.org/tapir/1.0 is not a valid
> metadata@http://rs.tdwg.org/tapir/1.0 document or a valid substitution.
>   at org.apache.xmlbeans.impl.store.Locale.autoTypeDocument(Locale.java:328)
>   at
> org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1279)
>   at
> org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1263)
>   at
> org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
>   at
> org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:309)
>   at org.tdwg.rs.tapir.x10.MetadataDocument$Factory.parse(Unknown Source)
>   at
> org.iobis.TapirClientUtilities.getMetadata(TapirClientUtilities.java:44)
>   at
> org.iobis.TapirClientUtilities.displayMetadataToSysout(TapirClientUtilities.java:72)
>   at org.iobis.TapirClient.main(TapirClient.java:100)
>
> Jacob Danner wrote:
>>
>> What errors are you seeing?
>>
>> On Fri, Jan 9, 2009 at 10:30 AM, Wm.A.Stafford
>> <st...@marine.rutgers.edu> wrote:
>>
>>>
>>> Jacob.
>>> The MetadataDocument is not valid.  What does this mean?
>>>
>>> -=beeky
>>>
>>> Jacob Danner wrote:
>>>
>>>>
>>>> Did you try validating it?
>>>>
>>>> Here is what I was referring to:
>>>> MetadataDocument mDoc =MetaDataDocument.Factory.parse(new
>>>> URL(server_url));
>>>> MetadataResultType doc = mDoc.getMetadataResultType();
>>>> System.out.println("title=" + doc.getTitle() );
>>>> System.out.println("doc=" + doc.toString()) ;
>>>>
>>>> On Fri, Jan 9, 2009 at 9:16 AM, Wm.A.Stafford
>>>> <st...@marine.rutgers.edu> wrote:
>>>>
>>>>
>>>>>
>>>>> Jacob,
>>>>> Thanks for the quick reply.  Unfortunately, I still don't see the
>>>>> solution.
>>>>> I think you are saying that the MetadataResultType.getTitle() function
>>>>> I
>>>>> mentioned is associated with type information not the actual value of
>>>>> the
>>>>> Title element.
>>>>> By this do you mean that there will not be a getTitle() function that
>>>>> returns the value of the Title element?
>>>>>
>>>>> I suppose I'm approaching this in a backward fashion.  I used XmlBeans
>>>>> to
>>>>> generate classes and javadoc and then searched the javadoc for a
>>>>> getTitle()
>>>>> function.
>>>>> How is this usually done, i.e. how do you go from schema element to
>>>>> java
>>>>> class to method that gets the element value?
>>>>>
>>>>> Thanks,
>>>>> -=beeky
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>>>
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by "Wm.A.Stafford" <st...@marine.rutgers.edu>.
jacob,

This is the exception that is thrown:

rg.apache.xmlbeans.XmlException: Element 
response@http://rs.tdwg.org/tapir/1.0 is not a valid 
metadata@http://rs.tdwg.org/tapir/1.0 document or a valid substitution.
    at 
org.apache.xmlbeans.impl.store.Locale.autoTypeDocument(Locale.java:328)
    at 
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1279)
    at 
org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1263)
    at 
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
    at 
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:309)
    at org.tdwg.rs.tapir.x10.MetadataDocument$Factory.parse(Unknown Source)
    at 
org.iobis.TapirClientUtilities.getMetadata(TapirClientUtilities.java:44)
    at 
org.iobis.TapirClientUtilities.displayMetadataToSysout(TapirClientUtilities.java:72)
    at org.iobis.TapirClient.main(TapirClient.java:100)

Jacob Danner wrote:
> What errors are you seeing?
>
> On Fri, Jan 9, 2009 at 10:30 AM, Wm.A.Stafford
> <st...@marine.rutgers.edu> wrote:
>   
>> Jacob.
>> The MetadataDocument is not valid.  What does this mean?
>>
>> -=beeky
>>
>> Jacob Danner wrote:
>>     
>>> Did you try validating it?
>>>
>>> Here is what I was referring to:
>>> MetadataDocument mDoc =MetaDataDocument.Factory.parse(new
>>> URL(server_url));
>>> MetadataResultType doc = mDoc.getMetadataResultType();
>>> System.out.println("title=" + doc.getTitle() );
>>> System.out.println("doc=" + doc.toString()) ;
>>>
>>> On Fri, Jan 9, 2009 at 9:16 AM, Wm.A.Stafford
>>> <st...@marine.rutgers.edu> wrote:
>>>
>>>       
>>>> Jacob,
>>>> Thanks for the quick reply.  Unfortunately, I still don't see the
>>>> solution.
>>>> I think you are saying that the MetadataResultType.getTitle() function I
>>>> mentioned is associated with type information not the actual value of the
>>>> Title element.
>>>> By this do you mean that there will not be a getTitle() function that
>>>> returns the value of the Title element?
>>>>
>>>> I suppose I'm approaching this in a backward fashion.  I used XmlBeans to
>>>> generate classes and javadoc and then searched the javadoc for a
>>>> getTitle()
>>>> function.
>>>> How is this usually done, i.e. how do you go from schema element to java
>>>> class to method that gets the element value?
>>>>
>>>> Thanks,
>>>> -=beeky
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>>>
>>>>
>>>>
>>>>         
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by Jacob Danner <ja...@gmail.com>.
What errors are you seeing?

On Fri, Jan 9, 2009 at 10:30 AM, Wm.A.Stafford
<st...@marine.rutgers.edu> wrote:
> Jacob.
> The MetadataDocument is not valid.  What does this mean?
>
> -=beeky
>
> Jacob Danner wrote:
>>
>> Did you try validating it?
>>
>> Here is what I was referring to:
>> MetadataDocument mDoc =MetaDataDocument.Factory.parse(new
>> URL(server_url));
>> MetadataResultType doc = mDoc.getMetadataResultType();
>> System.out.println("title=" + doc.getTitle() );
>> System.out.println("doc=" + doc.toString()) ;
>>
>> On Fri, Jan 9, 2009 at 9:16 AM, Wm.A.Stafford
>> <st...@marine.rutgers.edu> wrote:
>>
>>>
>>> Jacob,
>>> Thanks for the quick reply.  Unfortunately, I still don't see the
>>> solution.
>>> I think you are saying that the MetadataResultType.getTitle() function I
>>> mentioned is associated with type information not the actual value of the
>>> Title element.
>>> By this do you mean that there will not be a getTitle() function that
>>> returns the value of the Title element?
>>>
>>> I suppose I'm approaching this in a backward fashion.  I used XmlBeans to
>>> generate classes and javadoc and then searched the javadoc for a
>>> getTitle()
>>> function.
>>> How is this usually done, i.e. how do you go from schema element to java
>>> class to method that gets the element value?
>>>
>>> Thanks,
>>> -=beeky
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by "Wm.A.Stafford" <st...@marine.rutgers.edu>.
Jacob.
The MetadataDocument is not valid.  What does this mean?

-=beeky

Jacob Danner wrote:
> Did you try validating it?
>
> Here is what I was referring to:
> MetadataDocument mDoc =MetaDataDocument.Factory.parse(new URL(server_url));
> MetadataResultType doc = mDoc.getMetadataResultType();
> System.out.println("title=" + doc.getTitle() );
> System.out.println("doc=" + doc.toString()) ;
>
> On Fri, Jan 9, 2009 at 9:16 AM, Wm.A.Stafford
> <st...@marine.rutgers.edu> wrote:
>   
>> Jacob,
>> Thanks for the quick reply.  Unfortunately, I still don't see the solution.
>> I think you are saying that the MetadataResultType.getTitle() function I
>> mentioned is associated with type information not the actual value of the
>> Title element.
>> By this do you mean that there will not be a getTitle() function that
>> returns the value of the Title element?
>>
>> I suppose I'm approaching this in a backward fashion.  I used XmlBeans to
>> generate classes and javadoc and then searched the javadoc for a getTitle()
>> function.
>> How is this usually done, i.e. how do you go from schema element to java
>> class to method that gets the element value?
>>
>> Thanks,
>> -=beeky
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: user-help@xmlbeans.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by Jacob Danner <ja...@gmail.com>.
Did you try validating it?

Here is what I was referring to:
MetadataDocument mDoc =MetaDataDocument.Factory.parse(new URL(server_url));
MetadataResultType doc = mDoc.getMetadataResultType();
System.out.println("title=" + doc.getTitle() );
System.out.println("doc=" + doc.toString()) ;

On Fri, Jan 9, 2009 at 9:16 AM, Wm.A.Stafford
<st...@marine.rutgers.edu> wrote:
> Jacob,
> Thanks for the quick reply.  Unfortunately, I still don't see the solution.
> I think you are saying that the MetadataResultType.getTitle() function I
> mentioned is associated with type information not the actual value of the
> Title element.
> By this do you mean that there will not be a getTitle() function that
> returns the value of the Title element?
>
> I suppose I'm approaching this in a backward fashion.  I used XmlBeans to
> generate classes and javadoc and then searched the javadoc for a getTitle()
> function.
> How is this usually done, i.e. how do you go from schema element to java
> class to method that gets the element value?
>
> Thanks,
> -=beeky
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by "Wm.A.Stafford" <st...@marine.rutgers.edu>.
Jacob,
Thanks for the quick reply.  Unfortunately, I still don't see the 
solution. 

I think you are saying that the MetadataResultType.getTitle() function I 
mentioned is associated with type information not the actual value of 
the Title element.
By this do you mean that there will not be a getTitle() function that 
returns the value of the Title element?

I suppose I'm approaching this in a backward fashion.  I used XmlBeans 
to generate classes and javadoc and then searched the javadoc for a 
getTitle() function.
How is this usually done, i.e. how do you go from schema element to java 
class to method that gets the element value?

Thanks,
-=beeky


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Novice XmlBeans user question

Posted by Jacob Danner <ja...@gmail.com>.
Real quick reply, so forgive me if I am missing something specific.

What happens when you try to validate your type? I'm going to imagine
you get a couple of errors.

I think you should try using something like:
MetadataDocument doc = MetadataDocument.Factory.parse(new ...)

The differences between Types and Document are discussed in the
getting started docs.
Let the list know if that takes care of it or if you need further help,
-jacobd


On Thu, Jan 8, 2009 at 2:00 PM, Wm.A.Stafford
<st...@marine.rutgers.edu> wrote:
> I'm a novice user of XmlBeans.  I've used it successfully to parse several
> simple schemas but when I moved on to a more complicated schema I quickly
> came to a screeching halt.
>
> Here is a segment of the schema I am working with:
>
> <xsd:element name="metadata" type="metadataResultType">
>   <xsd:annotation>
>       <xsd:documentation>Global element to validate external metadata
> XMLfiles.</xsd:documentation>
>   </xsd:annotation>
> </xsd:element>
> <xsd:complexType name="metadataResultType">
>   <xsd:annotation>
>       <xsd:documentation>Format of metadata operation
> result.</xsd:documentation>
>   </xsd:annotation>
>   <xsd:sequence>
>       <xsd:element ref="dc:title">
>           <xsd:annotation>
>               <xsd:documentation>The name of this
> service</xsd:documentation>
>           </xsd:annotation>
>       </xsd:element>
>       <xsd:element ref="dc:type">
>           <xsd:annotation>
>               <xsd:documentation>The nature or genre of the
> content</xsd:documentation>
>           </xsd:annotation>
>       </xsd:element>
>                 ... lots more elements
>             </xsd:sequence>
> </xsd:complexType>
>
> Here is a segment of Java that XMLBeans generated.
>
> /**
> * An XML metadataResultType(@http://rs.tdwg.org/tapir/1.0).
> *
> * This is a complex type.
> */
> public interface MetadataResultType extends org.apache.xmlbeans.XmlObject
> {
>   public static final org.apache.xmlbeans.SchemaType type =
> (org.apache.xmlbeans.SchemaType)
>
> org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(MetadataResultType.class.getClassLoader(),
> "schemaorg_apache_xmlbeans.system.sC4F7BF7BC2573C292B659C414C97BA9A").resolveHandle("metadataresulttype5083type");
>     /**
>    * Gets the "title" element
>    */
>   org.purl.dc.elements.x11.SimpleLiteral getTitle();
>
> Here is a segment of java to extract the title from the server response.
>  MetadataResultType doc = MetadataResultType.Factory.parse(new URL(
> server_url  ));
> System.out.println("title=" + doc.getTitle() );
> System.out.println("doc=" + doc.toString()) ;
>
> This is the output of the code fragment.
> title=null
>
> doc=<response xsi:schemaLocation="http://rs.tdwg.org/tapir/1.0
> http://rs.tdwg.org/tapir/1.0/schema/tapir.xsd"
> xmlns="http://rs.tdwg.org/tapir/1.0"
> xmlns:dc="http://purl.org/dc/elements/1.1/"
> xmlns:dct="http://purl.org/dc/terms/"
> xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
> xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>  <header>.. contents removed...</header>
>  <metadata xml:lang="en">
>   <dc:title xml:lang="en">Photo-identification Library</dc:title>
>   <dc:type>http://purl.org/dc/dcmitype/Service</dc:type>
>     ... lots more elements removed
> </metadata>
> </response>
>
> I would like to get the title, type and ... lots more elements from the
> response.  My first attempt,
> calling getTitle(), seemed not only the obvious but the only choice.
> How to I get at title and the rest of the metadata sequence and why does
> getTitle() return null?
>
> Thanks for any help or advice,
> -=beeky
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org