Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java compilation error (XMLbeans/XML)

Status
Not open for further replies.

brianon

Programmer
Feb 6, 2002
22
0
0
IE
Hi,

I'm new to java and am trying to generate an XML instance doc from a schema using XMLbeans. Just trying to do this as basic as possible to start with before moving onto a much more complex schema.
I can't get this to compile...

My java code is...
import org.apache.xmlbeans.*;
import noNamespace.*;
import java.io.*;

public class HelloXMLBeans
{
EventDocument eventDoc;
EventDocument.Event eventElement;
XmlOptions xmlOptions;

public HelloXMLBeans()
{
eventDoc = EventDocument.Factory.newInstance();

eventElement = eventDoc.addNewEvent();

eventElement.setEventName(Event.EventName.GPRS);
eventElement.setId("Ten");

xmlOptions = new XmlOptions();
}


public void generateXMLDoc()
{
xmlOptions.setSavePrettyPrint();

xmlOptions.setSavePrettyPrintIndent(4);

String xmlStr = eventDoc.xmlText(xmlOptions);

System.out.println("Generated XML Instance Document is : " + "\n\n\n " + xmlStr);
}

public static void main(String[] args)
{
HelloXMLBeans hb = new HelloXMLBeans();
hb.generateXMLDoc();
}
}

My compilation error is...
javac -classpath /export/home/brianon/xmlbeans-2.0.0/lib/xbean.jar:testSchema.jar:. HelloXMLBeans.java
HelloXMLBeans.java:17: package Event does not exist
eventElement.setEventName(Event.EventName.GPRS);
^
1 error

My schema is...
<xs:schema xmlns:xs=" elementFormDefault="qualified" attributeFormDefaul
t="unqualified">

<xs:element name="Event">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="eventName"/>
<xs:element name="id" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<!-- All known events -->
<xs:simpleType name="eventName">
<xs:restriction base="xs:string">
<xs:enumeration value="Base"/>
<xs:enumeration value="MMS"/>
<xs:enumeration value="MMSSubmission"/>
<xs:enumeration value="MMSRetrieval"/>
<xs:enumeration value="GPRS"/>
<xs:enumeration value="TECGPRS"/>
</xs:restriction>
</xs:simpleType>

</xs:schema>

Ive been trying this for hours now and can't get it to work. Any help would be appreciated.

Cheers,
Brian.
 
Code:
  eventElement.setEventName(Event.EventName.GPRS);

What is Event.EventName.GPRS?

Cheers,
Dian
 
Thats where the problem is.
I got some example code from dev2bea.bea.com and for setting the enumerated types it uses something like this.
I thought from their example that...
eventElement.setEventName(Event.EventName.GPRS);

was correct tp selct the <xs:enumeration value="GPRS"/>

When compiling it seems to not like this. I'm not sure what should go here to set the enum to GPRS or any other value for that matter.

Cheers,
Brian.
 
Maybe

Code:
eventElement.setEventName(EventElement.Event.EventName.GPRS);

Anyway you should identify what is Event (I assume it's a class) and EventName (is that a field or another class?) because the code looks a little confusing.

Cheers,
Dian
 
I fixed it (at least it comppiles) :)

eventElement.setName(EventName.GPRS);

However, when I run it I now get the following...
[tt]
java HelloXMLBeans.java
Exception in thread "main" java.lang.NoClassDefFoundError: HelloXMLBeans/java
[/tt]

[tt]ls[/tt] of the current dir is...
[tt]
ls
HelloXMLBeans.class HelloXMLBeans.java testSchema.jar testSchema.xsd
[/tt]
Any ideas ?
 
Managed to get it to run ...

java -cp $XMLBEANS_HOME/lib/xbean.jar:$XMLBEANS_HOME/lib/jsr173_api.jar:testSchema.jar:. HelloXMLBeans
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top