0

I'm using node.js to use the Watson Dialog system. I'm using a function to create a new dialog but somewhere along the code I'm getting a weird error related to the xml file that reads

{ code: 400,
  error: 'Failed to import file. Possibly due to corrupt or invalid file or system error. - java.lang.IllegalStateException: reader must be on a START_ELEMENT event, not a -1 event',
  conversionLog: 'WARN: No valid xsd schema specified in XML header. Assuming version="WatsonDialogDocument_1.1".\n' }

I'm using the pizza dialog xml that is available as an example for the dialog system to test so I don't think the problem is that the file is invalid. Here is the code I use to create the dialog.

  var params = {
  name: req.body.username,
  file: fs.createReadStream(__dirname+'/public/dialogs/users/'+req.body.username+'/'+req.body.username+'.xml')
  };

  dialog_service.createDialog(params, function(err, dialog) {
  if (err)
    console.log(err)
  else
    console.log(dialog);
  });

I also have the WatsonDialogDocument_1.0.xsd document on the same folder as the xml dialog file. At the xml file for the dialog you can also find this

<dialog xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Atirag
  • 1,660
  • 7
  • 32
  • 60

1 Answers1

1

try to bump up a version to WatsonDialogDocument_1.1.xsd. You should also try to first POST your xml from a REST client. cURL or Rest Console. Just to make sure the problem is in the xml and not in the code.

BTW, you don't need the XSD file to do the POST.

<dialog xsi:noNamespaceSchemaLocation="WatsonDialogDocument_1.1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Dudi
  • 2,340
  • 1
  • 24
  • 39
  • I wanted to use the 1.1 version but I don't know where to find it. – Atirag Feb 04 '16 at 14:25
  • I just send the name of the xml by POST. The xml file is copied beforehand by a function to this path /public/dialogs/users/'+req.body.username+'/'+req.body.username+'.xml and then just read by the createReadStream function – Atirag Feb 04 '16 at 14:41
  • you don't need the xsd to post a dialog, so you can use 1.1. pls check that you can POST the xml created by your code by a different REST client. For example:curl -X POST -F "file=@/yourpath/dialog.xml" -F "name=whatever” https://gateway.watsonplatform.net/dialog/api/v1/dialogs/ -u “username:password” – Dudi Feb 04 '16 at 15:56
  • I'm sorry I'm not so sure how to use curl. When I run that I get this. curl: no URL specified! – Atirag Feb 04 '16 at 16:36
  • I tried something else and it worked. I wanted to use the pizza xml as a template for creating dialogs for several users. So my program copies the xml file to user folders and then tries to create the dialog using this copied file. I tried to initialize a dialog using the template file without copying first and it worked. It seems that the copying process could be too slow and when it tries to create the dialog the file is probably not yet properly copied?? – Atirag Feb 04 '16 at 16:42