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 = "http://cloud.ocrsdk.com/processFields?taskId=$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="http://ocrsdk.com/schema/taskDescription-1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ocrsdk.com/schema/taskDescription-1.0.xsd http://ocrsdk.com/schema/taskDescription-1.0.xsd">
  <page applyto="0">
    <text id="Google" left="64" top="44" right="110" bottom="103">
      <regExp>[0-9]+\.[0-9+]%</regExp>
    </text>
  </page>
</document>

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

asked 20 Mar '14, 12:28

hfuhruhurr's gravatar image

hfuhruhurr
1112


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

Ready XML samples can always be found here: http://ocrsdk.com/documentation/specifications/xml-scheme-field-settings/

link

answered 20 Mar '14, 14:47

Anastasia%20Galimova's gravatar image

Anastasia Ga... ♦♦
790112

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.)

(20 Mar '14, 17:59) hfuhruhurr

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
(20 Mar '14, 18:20) Anastasia Ga... ♦♦

Hm.

Just to double-check, I used the short example given under the URL http://ocrsdk.com/documentation/specifications/xml-scheme-field-settings/ "as is"

<document xmlns="http://ocrsdk.com/schema/taskDescription-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ocrsdk.com/schema/taskDescription-1.0.xsd http://ocrsdk.com/schema/taskDescription-1.0.xsd"> <fieldTemplates></fieldTemplates> <page applyTo="0,1,3,4">
       <text id="myTextBlock" left="0" top="0" right="20" bottom="50">
             <language>English,German</language>
             <textType>matrix</textType>
             <oneTextLine>true</oneTextLine>
       </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?

link

answered 20 Mar '14, 19:09

hfuhruhurr's gravatar image

hfuhruhurr
1112

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?

(20 Mar '14, 19:17) hfuhruhurr
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×49
×37
×33

Asked: 20 Mar '14, 12:28

Seen: 4,491 times

Last updated: 20 Mar '14, 19:17

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal