XML parsing using GWT

56 views
Skip to first unread message

G

unread,
Jun 25, 2009, 6:50:03 PM6/25/09
to Google Web Toolkit
Hello -

I am little frustrated with GWT, firstly importing external jar in GWT
isn't trivial and secondly simple XML parsing doesnt work.

At this point, I dont care much about importing external jars and will
leave that for later.

What I dont understand is why simple XML parsing is not working ... I
am getting no compile time errors.. using GWT gwt-windows-1.5.3.

In my project .gwt.xml I added <inherits
name="com.google.gwt.xml.XML" />

I am running in the hosted mode and it bombs with the exception:
java.lang.ClassCastException:
com.google.gwt.xml.client.impl.DocumentImpl cannot cast to
com.google.gwt.dom.client.Document

Even this doesn't work:
Document messageDom = (Document) XMLParser.parse("<?xml version='1.0'?
><message></message>");

Thanks

John Ivens

unread,
Jun 25, 2009, 7:00:13 PM6/25/09
to Google-We...@googlegroups.com
I seem to remember that there are two different XML libraries..

I used these imports:

import com.google.gwt.xml.client.CDATASection;

import com.google.gwt.xml.client.Document;

import com.google.gwt.xml.client.Element;

import com.google.gwt.xml.client.NodeList;

import com.google.gwt.xml.client.Text;

import com.google.gwt.xml.client.XMLParser;


This inherits tag:


<inherits name='com.google.gwt.xml.XML'/>

G

unread,
Jun 25, 2009, 8:14:39 PM6/25/09
to Google Web Toolkit
That was helpful. Thanks. Wonder why the name of classes was named
like this...

Anyway, my current problem is :

Node n = (Node) node.getFirstChild();
Window.alert(n);
String text = n.getNodeValue();

"text" returns null even though when I try to print "n" there is some
text. whats wrong with getNodeValue() ??!




On Jun 25, 6:00 pm, John Ivens <john.wagner.iv...@gmail.com> wrote:
> I seem to remember that there are two different XML libraries..
> I used these imports:
>
> import com.google.gwt.xml.client.CDATASection;
>
> import com.google.gwt.xml.client.Document;
>
> import com.google.gwt.xml.client.Element;
>
> import com.google.gwt.xml.client.NodeList;
>
> import com.google.gwt.xml.client.Text;
>
> import com.google.gwt.xml.client.XMLParser;
>
> This inherits tag:
>
> <inherits name='com.google.gwt.xml.XML'/>
>

Rahul

unread,
Jul 30, 2009, 11:24:11 AM7/30/09
to Google Web Toolkit
Hi,
I am also getting the same error

com.google.gwt.xml.client.impl.DocumentImpl cannot cast to
com.google.gwt.dom.client.Document

This is my code

public void onResponseReceived(Request request,
Response response) {
// TODO Auto-generated method stub
Document xmlDoc = (Document) XMLParser.parse(response.getText
());
Element root = (Element) xmlDoc.getDocumentElement();
final int randNum = Random.nextInt(25);
Element randomVid = (Element) root.getElementsByTagName
("video").getItem(randNum);

}

I tired importing the what John has written but its not accepinting
half of these imports, saying that remove unsed imports.

any idea what should i do ?
Reply all
Reply to author
Forward
0 new messages