utf 8 - Issues when adding a xml content with UTF-8 characters to an eXist-db collection using Perl -


i trying add dynamically generated xml content exist-db collection (see code below addfile.pl) using perl, issue whenever content contains utf-8 characters receive error failed parse xml-rpc request: byte "195" not member of (7-bit) ascii character set..

#!/usr/bin/perl use rpc::xml; use rpc::xml::client;  ($sec, $min, $hour, $mday, $mon, $year) = localtime(); $timestamp = sprintf("%04d%02d%02d%02d%02d%02d",$year+1900,$mon+1,$mday,$hour,$min,$sec); print("timestamp: $timestamp\n");  $filename = "$timestamp.xml"; $collection = 'output';  $record = <<end; <document id="doc_20150419014112">   <text>ñáéíóú</text> </document> end  $query = <<end; xquery version "3.0"; import module namespace xmldb="http://exist-db.org/xquery/xmldb"; declare variable \$filename := '$filename'; declare variable \$record := '';  let \$log-in := xmldb:login("/db", "admin", "admin") (: let \$create-collection := xmldb:create-collection("/db", "$collection") :) let \$record :=  $record  \$target in ('/db/$collection')   return xmldb:store(\$target, \$filename, \$record) end  print $query;  $url = "http://admin:admin\@localhost:8080/exist/xmlrpc"; # connecting $url... $client = new rpc::xml::client $url; # output options $options = rpc::xml::struct->new(     'indent' => 'yes',      'encoding' => 'utf-8',     'highlight-matches' => 'none'); $req = rpc::xml::request->new("query", $query, 20, 1, $options); $response = $client->send_request($req); if($response->is_fault) {     die "an error occurred: " . $response->string . "\n"; } $result = $response->value; print $result; 

when run xquery script (see below) directly exide runs when run through perl script receive following:

$ perl addfile.pl   timestamp: 20150428162016 xquery version "3.0"; import module namespace xmldb="http://exist-db.org/xquery/xmldb"; declare variable $filename := '20150428162016.xml'; declare variable $record := '';  let $log-in := xmldb:login("/db", "admin", "admin") (: let $create-collection := xmldb:create-collection("/db", "output") :) let $record :=  <document id="doc_20150419014112">   <text>ñáéíóú</text> </document>   $target in ('/db/output')   return xmldb:store($target, $filename, $record) error occurred: failed parse xml-rpc request: byte "195" not member of (7-bit) ascii character set. 

i found solution here, quote answer in case:

the rpc::xml perl module uses us-ascii xml encoding default. if delivering utf-8 content database or other sources, rpc::xml produces invalid xml default setting.

the xml encoding used rpc::xml can changed globally:

#!/usr/bin/perl use rpc::xml; use rpc::xml::client; $rpc::xml::encoding = 'utf-8'; 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -