No source code is available for type javax.xml.parsers.DocumentBuilderFactory

444 views
Skip to first unread message

Vrushali Patil

unread,
Sep 1, 2011, 11:48:31 AM9/1/11
to Google Web Toolkit
Hi,

I am new to Java and GWT. I am trying to parse a xml, which I have
written as stringbuilder.

1) I tried using XMLParser.parse(xmlstring); but it gave a
DOMException tat string is crossing max length. Is there any way to
work around this.

2) I used DocumentBuilderFactory ... the code is as follows. It gives
the error as

No source code is available for type
javax.xml.parsers.DocumentBuilderFactory - It is some sort of
Inheritance issue. But I am unaware of what exactly inherit name i
should be using. Please guide.

------------------------- code
---------------------------------------------------
edu.xml.gwt.ibm.tutorialDemo1.client;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;


import com.google.gwt.core.client.EntryPoint;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TutorialDemo1 implements EntryPoint {

xmlquery callquery = new xmlquery();
String xmlstring;
/**
* This is the entry point method.
*/
public void onModuleLoad() {

xmlstring = callquery.xmlget_capabilities();
System.out.println(xmlstring);

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(xmlstring));
//doc = builder.parse(new
ByteArrayInputStream(xml.getBytes("UTF-8")));
try {
DocumentBuilder builder = factory.newDocumentBuilder();
try {
Document doc = builder.parse(inStream);

System.out.println("");
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
----------------------- xml string return function
-------------------------------------------------

public String xmlget_capabilities(){

StringBuilder xmlquery = new StringBuilder("") ;
xmlquery.append("<?xml version='1.0' encoding='UTF-8'?>"
+ "<GetCapabilities xmlns='http://www.opengis.net/sos/1.0>"
+ "<ows:AcceptVersions>"
+ "<ows:Version>1.0.0</ows:Version>"
+ "</ows:AcceptVersions>"
+ "<ows:Sections>"
+ "<ows:Section>OperationsMetadata</ows:Section>"
+ "<ows:Section>ServiceIdentification</ows:Section>"
+ "<ows:Section>ServiceProvider</ows:Section>"
+ "<ows:Section>Filter_Capabilities</ows:Section>"
+ "<ows:Section>Contents</ows:Section>"
+ "</ows:Sections>"
+ "</GetCapabilities>");

return xmlquery.toString();

}

---------------------------------------------------------------------------------------------------------------------------------

Thanks,
Vrushali

Jens

unread,
Sep 1, 2011, 12:46:11 PM9/1/11
to google-we...@googlegroups.com
In general you can only use Java classes on the client side (everything that is in your client and shared package) listed in: http://code.google.com/intl/de-DE/webtoolkit/doc/latest/RefJreEmulation.html

So you can not use most of the classes in your code on client side. 

You have to:
- write your own client side string parser that converts the xml string to something you want to have 
- parse the XML on server side and ask the server for the information you need

I haven't used XMLParser yet but it seems to me that the xml string you want to parse isn't that long so I think it should work.

-- J.

Vrushali Patil

unread,
Sep 1, 2011, 1:52:22 PM9/1/11
to google-we...@googlegroups.com
Hi I tried using XMLParser as u suggested. But getting this error.

The code is
public void onModuleLoad() {
    
        xmlstring = callquery.xmlget_capabilities();
        System.out.println(xmlstring);
        System.out.println(xmlstring.length());

        
        xmldoc = XMLParser.parse(xmlstring); \\ Error at this line
        Element root = xmldoc.getDocumentElement();
        System.out.println("Element = "+ root.getNodeName());  
    }

See Development Mode for details.

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:193)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:510)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.xml.client.impl.DOMParseException: Failed to parse: 1.
at com.google.gwt.xml.client.impl.XMLParserImpl.parse(XMLParserImpl.java:280)
at com.google.gwt.xml.client.XMLParser.parse(XMLParser.java:47)
at edu.xml.gwt.ibm.tutorialDemo1.client.TutorialDemo1.onModuleLoad(TutorialDemo1.java:61)
... 9 more
Caused by: com.google.gwt.core.client.JavaScriptException: (Error): line 1, char 94:The character :GetCapabilities b < more 11 ... com.google.gwt.xml.client.impl.XMLParserImpl.parse(XMLParserImpl.java:278) at com.google.gwt.xml.client.impl.XMLParserImplIE6.parseImpl(XMLParserImplIE6.java) com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132) com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237) value. attribute an in used be cannot 1.
at com.google.gwt.xml.client.impl.XMLParserImpl.parse(XMLParserImpl.java:280)
at com.google.gwt.xml.client.XMLParser.parse(XMLParser.java:47)
at edu.xml.gwt.ibm.tutorialDemo1.client.TutorialDemo1.onModuleLoad(TutorialDemo1.java:61)



Caused by: com.google.gwt.core.client.JavaScriptException: (Error): line 1, char 94:The character ">
1. at com.google.gwt.xml.client.impl.XMLParserImpl.parse(XMLParserImpl.java:280) at com.google.gwt.xml.client.XMLParser.parse(XMLParser.java:47) at edu.xml.gwt.ibm.tutorialDemo1.client.TutorialDemo1.onModuleLoad(TutorialDemo1.java:61) ... 9 more Caused by: com.google.gwt.core.client.JavaScriptException: (Error): line 1, char 94:The character :GetCapabilities>

Vrushali Patil

unread,
Sep 1, 2011, 1:58:24 PM9/1/11
to google-we...@googlegroups.com
Hi I tried using XMLParser as u suggested. But getting this error.

The code is
public void onModuleLoad() {
    
        xmlstring = callquery.xmlget_capabilities();
        System.out.println(xmlstring);
        System.out.println(xmlstring.
Vrushali


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/aegt2NbIkfMJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Reply all
Reply to author
Forward
0 new messages