I wonder if there is a good way for parsing org.w3c.dom.Document
to org.enhydra.wireless.voicexml.dom.VoiceXMLDocument
?
I'm using Java
in Android
Application. My application is reading a VoiceXML
file into InputStream
. From InputStream
, I can get Document using DocumentBuilderFactory
. But this time I stuff at parsing Document
to VoiceXMLDocument
. Below is my soft code.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnLoadFile = (Button) findViewById(R.id.btnLoadFile);
btnLoadFile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
InputStream input = downloadFile(fileUrl);
try {
Document dom = getVXML(input);
/**
* I'm stuff at here.
* Cannot parsing Document to VoiceXMLDocument.
* It will make an error
* */
VoiceXMLDocument voiceXMLDocument = (VoiceXMLDocument) dom;
} catch (Exception e) {
Log.e("Exception = ", e.getMessage());
}
}
});
}
/**
* Convert InputStream to Document
* @param inputStream (InputStream)
* @return dom (Document)
* */
public Document getVXML(InputStream inputStream)
throws FileNotFoundException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document dom = null;
try {
DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse(inputStream);
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return dom;
}
I have spend a little time for this topic and have found a good way to get VoiceXMLDocument from vxml file without parsing Document. Below is the way how I get this thing done.
First Step: Import these jar files: jvxml-jsapi1.0.jar - jvxml-xml.jar - jvxml.jar - log4j-1.2.13.jar. I think you can find these jar files on internet.
Second Step: Download file vxml and read it as InputStream
Third Step: Parsing Input Stream to VoiceXmlDocument
Final Step: Get element from VoiceXMLDocument as you want
This way will print information of prompt tag from vxml file. You can see it in Android Log.
Good Luck!