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.
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.