Hi,
I am trying to read the Type of an element ie. integer type, however, i
have 2 results depending whether i declare my xml instance with a using
a "noNamespaceSchemaLocation" or a "schemaLocation" attribute.
If i declare xml instance with a "noNamespaceSchemaLocation" attribute,
i would get the right type i.e. java.math.BigInteger, however if i
declare the xml instance with a "schemaLocation" attribute, then i will
get a java.lang.String which is incorrect.
Is this a bug or a feature? did i miss something? would be grateful if
someone could help to shed some light... Below are the details of the
schema, xml-instance and my java app. am using dom4j v 1.3
Thanks in advance..
chung-onn
schema
---------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://my.integer.org"
elementFormDefault="qualified">
<xsd:element name="myInfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="myInteger" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
xml-instance with noNamespace
------------------------------------------
<myInfo
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='file:/MyIntegerSchema.xsd'>
<myInteger>5</myInteger>
</myInfo>
xml-instance with namespace
--------------------------------------
<myInfo xmlns='http://my.integer.org'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://my.integer.org file:/MyIntegerSchema.xsd'>
<myInteger>5</myInteger>
</myInfo>
java app
----------
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
import org.dom4j.Node;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.List;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
public class MyInteger {
/** Creates a new instance of MyInteger */
public MyInteger() {
try {
DocumentFactory factory = DatatypeDocumentFactory.getInstance();
SAXReader reader = new SAXReader(factory);
String urlString =
"file:/Volumes/Data/Projects/grasshopper-01/MyIntegerXSI.xml";
URL url = new java.net.URL(urlString);
Document document = reader.read(url);
HashMap ns = new HashMap();
// ns.put("my","http://my.integer.org");
factory.setXPathNamespaceURIs(ns);
List list = document.selectNodes("/my:myInfo/my:myInteger");
System.out.println("List count:" + list.size());
for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
System.out.println("Found node");
Node node = (Node) iter.next();
if ( node instanceof Element ) {
Element element = (Element) node;
printType( element, element.getData());
}
else {
System.out.println( "Did not find an attribute or
element: " + node);
}
}
}catch (DocumentException e){
e.printStackTrace();
}catch (java.net.MalformedURLException e){
e.printStackTrace();
}
}
private void printType(Element ele, Object o) {
//System.out.println("Type:" + ele.getXSDatatype());
System.out.println("element:" + ele.getName());
System.out.println("Type:" + o +" Value:" + o.getClass().getName());
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new MyInteger();
}
}
--
Your favorite stores, helpful shopping tools and great gift ideas.
Experience the convenience of buying online with Shop@Netscape!
http://shopnow.netscape.com/
-------------------------------------------------------
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