In relatively new 20.04.1 installation, xmllint will not read files

Asked by Syd Bauman

Is this a bug, or something I am doing wrong? Or both?

The `xmllint` command (of libxml2 fame) will not open any local files. The `xmlstarlet` command also will usually not open files, I presume because it is relying on libxml2 to open and parse them, but I do not know that.

Here is a shell console listing to demonstrate the problem.

$ #
$ # version of system and xmllint itself
$ #
$ cat /etc/os-release
| NAME="Ubuntu"
| VERSION="20.04.1 LTS (Focal Fossa)"
| ID=ubuntu
| ID_LIKE=debian
| PRETTY_NAME="Ubuntu 20.04.1 LTS"
| VERSION_ID="20.04"
| HOME_URL="https://www.ubuntu.com/"
| SUPPORT_URL="https://help.ubuntu.com/"
| BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
| PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
| VERSION_CODENAME=focal
| UBUNTU_CODENAME=focal
$ which xmllint
| /snap/bin/xmllint
$ xmllint --version
| /snap/libxml2/69/bin/xmllint: using libxml version 20909-GITv2.9.9
| compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma
$ #
$ # input document
$ #
$ cat /tmp/tiny_duck.xml
| <?xml version="1.0" encoding="UTF-8"?>
| <duck>
| <sound>quack</sound>
| </duck>
|
$ #
$ # try it (it fails)
$ #
$ xmllint --format /tmp/tiny_duck.xml
| I/O error : Permission denied
| I/O error : Permission denied
| warning: failed to load external entity "/tmp/tiny_duck.xml"
$ #
$ # Could it actually be a permissions problem?
$ # No, I just `cat`ted that file. But double-check,
$ # anyway.
$ #
$ ls -l /tmp/tiny_duck.xml
| -rw-rw-r-- 1 syd syd 78 Jan 6 08:27 /tmp/tiny_duck.xml
$ whoami
| syd
$ #
$ # try a different command that reads and parses XML on same file
$ #
$ which xmlwf
| /usr/bin/xmlwf
$ xmlwf -v
| xmlwf using expat_2.2.9
| sizeof(XML_Char)=1, sizeof(XML_LChar)=1, XML_DTD, XML_CONTEXT_BYTES=1024, XML_NS
$ xmlwf -s -m -d /tmp/ERASE.ME/ /tmp/tiny_duck.xml
$ cat /tmp/ERASE.ME/tiny_duck.xml
| <document>
| <starttag name="duck" uri="/tmp/tiny_duck.xml" byte="39" nbytes="6" line="2" col="0"/>
| <chars str="&#10;" uri="/tmp/tiny_duck.xml" byte="45" nbytes="1" line="2" col="6"/>
| <chars str=" " uri="/tmp/tiny_duck.xml" byte="46" nbytes="2" line="3" col="0"/>
| <starttag name="sound" uri="/tmp/tiny_duck.xml" byte="48" nbytes="7" line="3" col="2"/>
| <chars str="quack" uri="/tmp/tiny_duck.xml" byte="55" nbytes="5" line="3" col="9"/>
| <endtag name="sound" uri="/tmp/tiny_duck.xml" byte="60" nbytes="8" line="3" col="14"/>
| <chars str="&#10;" uri="/tmp/tiny_duck.xml" byte="68" nbytes="1" line="3" col="22"/>
| <endtag name="duck" uri="/tmp/tiny_duck.xml" byte="69" nbytes="7" line="4" col="0"/>
| </document>
$

Help *greatly* appreciated, for although I am sure I can live without `xmllint` and `xmlstarlet`, I cannot get any work done without them. I will be forced to revert to 16.04 (or some other earlier release; or some other flavor of GNU/Linux).

Thank you.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu libxml2 Edit question
Assignee:
No assignee Edit question
Solved by:
Syd Bauman
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

You are not using the *.deb version from the Ubuntu repositories, but the snap version, hence you are wrong here.
For applications in snap format you better ask at https://forum.snapcraft.io

And yes, it is an access rights problem. Snap applications usually are not allowed accessing the /tmp directory.
Copy the file into your home directory and xmllint might be able to read it.

Revision history for this message
Syd Bauman (syd-bauman) said :
#2

Thank you, m-hampl!

You have both solved my problem, and incorrectly identified it. It was not an outright access problem with /tmp/, as it did not matter if the input file was in /tmp/ or in ~/Documents/, I got the same result. (And, as a side question which belongs in the snapverse, I suppose, why on earth would an application not be allowed to access /tmp/? Seems nuts to me.) However, uninstalling the snap version of libxml2 and installing both libxml2 and libxml2-utils with the usual `sudo apt install` did the trick.

I suppose to be a good dooby I should go report this problem on snapcraft as you suggest. That said, I have not gotten any work done for days, I would like to just get back to it ... :-|

Thank you again.