Hi all,

i really appreciate if someone can help me with this problem. I have been trying unsucessfully to read the Element's Type from an xml instance, i tried reading the docs and mail-list but doesnt seems to help. Essentially, i am trying to read the type of an element (e.g Integer, Date, String etc) using both Element or DatatypeElement . When using Element, i only managed to get the type as java.lang.String but when i use DatatypeElement , i get a ClassCastException error. Any clue? Below are the details

my Schema is
------------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://my.earth.org";
xmlns="http:// my.earth.org"
elementFormDefault="qualified">
<xsd:element name="myInfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="myName" type="xsd:string"/>
<xsd:element name="myAge" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>


my xml instance is
------------------

<myInfo xmlns='http://my.earth.org'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://my.earth.org file:/MyIntegerSchema.xsd'>
<myName>Cheong Chung Onn</myName>
<myAge>5</myAge>
</myInfo>

my java app is
--------------
public class MyInteger {
/** Creates a new instance of MyInteger */
public MyInteger() {
try {
SAXReader reader = new SAXReader();

reader.setDocumentFactory(DatatypeDocumentFactory.getInstance());
String urlString = "file:/MyIntegerXSI.xml";
URL url = new java.net.URL(urlString);
Document document = reader.read(url);
System.out.println("Getting root element");
DatatypeElement root = (DatatypeElement) document.getRootElement();
printType(root);
}catch (DocumentException e){
e.printStackTrace();
}catch (java.net.MalformedURLException e){
e.printStackTrace();
}
}

private void printType(DatatypeElement ele) {
//System.out.println("Type:" + ele.getXSDatatype());
System.out.println("Value:" + ele.getData().getClass());
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new MyInteger();
}

my error msg is
---------------
Exception in thread "main" java.lang.ClassCastException: org.dom4j.tree.DefaultElement
at MyInteger.<init>(MyInteger.java:34)
at MyInteger.main(MyInteger.java:52)



-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to