PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/dotNet/dotNetWrapper/FieldLevelXml.cs

https://github.com/tamisoft/ocrsdk.com
C# | 37 lines | 27 code | 5 blank | 5 comment | 4 complexity | 378cecb5799d39ca4d8ae30e4863486f MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. namespace Abbyy.CloudOcrSdk
  7. {
  8. public class FieldLevelXml
  9. {
  10. /// <summary>
  11. /// Read text result from field-level xml
  12. /// </summary>
  13. /// <param name="filePath"></param>
  14. /// <returns></returns>
  15. public static string ReadText(string filePath)
  16. {
  17. XDocument xDoc = XDocument.Load(filePath);
  18. var ns = xDoc.Root.GetDefaultNamespace();
  19. var field = xDoc.Root.Element(ns+"field");
  20. var value = field.Element(ns+"value");
  21. string result = value.Value;
  22. var xEncoding = value.Attribute("encoding");
  23. if (xEncoding != null && xEncoding.Value.ToLower() == "base64")
  24. {
  25. byte[] bytes = Convert.FromBase64String(result);
  26. System.Text.Encoding encoding = new System.Text.UnicodeEncoding();
  27. result = encoding.GetString(bytes);
  28. }
  29. return result;
  30. }
  31. }
  32. }