PHP processFields returns error 450 with msg "Data at the root level is invalid. Line 1, position 1."

  • Last Post 20 March 2014
hfuhruhurr posted this 20 March 2014

This is driving me nuts and I hope someone can help me. What I did so far using PHP/curl: I upload an image using the submitImage method. The call is successful (200) and returns a taskId. I then try to use processFields to recognize textareas in the image. The code looks like this.

  $url = "$taskid";
  $curlHandle = curl_init();
  curl_setopt($curlHandle, CURLOPT_VERBOSE, 1);
  curl_setopt($curlHandle, CURLOPT_URL, $url);
  curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curlHandle, CURLOPT_USERPWD, "$applicationId:$password");
  curl_setopt($curlHandle, CURLOPT_POST, 1);
  curl_setopt($curlHandle, CURLOPT_USERAGENT, "PHP Cloud OCR SDK Sample");
  curl_setopt($curlHandle, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); 
  curl_setopt($curlHandle, CURLOPT_HEADER, 1); 
  curl_setopt($curlHandle, CURLOPT_POSTFIELDS, array("my_file"=>"@".$local_directory."/fields.xml")); 
  $response = curl_exec($curlHandle);

The fields.xml looks like this.

<?xml version="1.0" encoding="utf-8"?>
<document xmlns=""
  <page applyto="0">
    <text id="Google" left="64" top="44" right="110" bottom="103">

The call to processFields returns an error 450 with the error message "Data at the root level is invalid. Line 1, position 1." According to the documentation this indicates:

  1. The identifier of the task has not been specified.
  2. Incorrect XML file has been transmitted
  3. The task with the specified identifier cannot be started (e.g. it has already been started).
  4. Task description length exceeds 255 characters.

The taskId is correct (1), and the task shouldn't have been already started (3) since I get a new identifier every time I run my script. I do not use a description (4). This leaves me, most likely, with an incorrect XML.

I tried to omit "<?xml version="1.0" encoding="utf-8"?>" but still get a 450 with 'data at the root level is invalid'. I removed the regExp, still 450. I changed the encoding from UTF-8 to Latin1, still 450. I changed the line endings form CRLF to LF, still 450. I changed <page applyto="0"> to just <page>, still 450.

Searching this forum for "data root level" and alike yielded no results at all. Anyone out there, who can help me?

Many thanks in advance! Hans

Order By: Standard | Newest | Votes
Anastasia Galimova posted this 20 March 2014

The solution is to replace "applyto" to "applyTo".

Ready XML samples can always be found here:

hfuhruhurr posted this 20 March 2014

Hi Anastasia,

many thanks for your suggestion! I changed from applyto to applyTo but, unfortunately, I get the same result. Here's the XML that is returned by the call to processFields method:

HTTP/1.1 100 Continue

HTTP/1.1 450 Data at the root level is invalid. Line 1, position 1.
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/xml; charset=utf-8
Expires: -1
X-Thumbs-Up: Thumbs up for looking this deep!
Date: Thu, 20 Mar 2014 13:54:24 GMT
Content-Length: 145

<?xml version="1.0" encoding="utf-8"?><error><message language="english">Data at the root level is invalid. Line 1, position 1.</message></error>

Perhaps this XML sheds some more light on what is going wrong.

(I used one of the examples to be found at the mentioned URL as a basis but, apparently, made a typo.)

Anastasia Galimova posted this 20 March 2014

The processFields method is implemented in our C#, Java and Android samples. You can test, if your XML-file is correct, using, for example, ConsoleTest application from our C# sample: just specify the credentials in Test.cs file and call the application with arguments like this:

ConsoleTest.exe --asFields D:\image.png D:\settings.xml D:\target_dir

hfuhruhurr posted this 20 March 2014


Just to double-check, I used the short example given under the URL "as is"

<document xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <fieldTemplates></fieldTemplates> <page applyTo="0,1,3,4">
       <text id="myTextBlock" left="0" top="0" right="20" bottom="50">
       </text> </page> </document>

With the same very same error message result. I must be doing something wrong.

It would be extremely helpful if there was a working PHP example using processFields. Is such code available?

hfuhruhurr posted this 20 March 2014

Looking this forum as well as Google up and down it seems as if no one has been able to successfully use the processFields method with PHP.

Is that really possible?