I get 'xmlParseCharRef' error when accessing S3 bucket from R, how to fix it?

Viewed 20
> sessionInfo()

R version 3.6.0 (2019-04-26)

Platform: x86_64-redhat-linux-gnu (64-bit)

Running under: Amazon Linux 2

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] aws.ec2metadata_0.2.0 aws.s3_0.3.21        
[3] paws_0.1.12          

loaded via a namespace (and not attached):
 [1] httr_1.4.2          compiler_3.6.0      R6_2.5.1           
 [4] paws.storage_0.1.12 tools_3.6.0         base64enc_0.1-3    
 [7] curl_4.3.2          aws.signature_0.6.0 xml2_1.3.3         
[10] digest_0.6.29       jsonlite_1.8.0      paws.common_0.3.17





 > Sys.setenv('AWS_DEFAULT_REGION'='ap-northeast-2')
    
 > bucket_exists("my-bucket")
    
    [1] TRUE
    
 > mybucket <- get_bucket("my-bucket")

Error in read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html, : xmlParseCharRef: invalid xmlChar value 8 [9]

-> The existence of the bucket can be checked well, but an error occurs when trying to access the actual bucket.

How to solve this?

what is problem?

1 Answers

The problem is that XML 1.0 does not allow Unicode codepoint 8 as a valid XML character, whether or not it's written as a character reference.

XML 1.1 does allow it, but XML 1.1 was not widely adopted.

As with all incoming documents that fail XML parsing, your choice is to fix the sender so it doesn't generate bad XML (preferred), or to repair the bad XML on arrival (using tools that accept non-XML input, e.g. Perl/sed). Before you can repair it, you need to know why the sending application is including an u0008 in the document, and what it expects the recipient to do with it.

Related