Unable to extract some properties from Maven settings.xml using either xmllint or xmlstarlet

I have a Maven settings file at ~/.m2/settings.xml. I need to write some scripting that extracts the username and password from one of the server entries.

I’ve tried using both “xmllint” and “xmlstarlet” using what I believe are the correct (different) command-line parameters for both of those. The result for both is just an empty string. There is no error, it just prints nothing.

This is an excerpt of ~/.m2/settings.xml:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <!--
    Licensed to the Apache Software Foundation (ASF) under one
    ...
    --><!--
     | This is the configuration file for Maven. It can be specified at two levels:
    ...
     |-->
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

      <servers>
        <server>
                    <id>central</id>
                    <username>...</username>
                    <password>...</password>
        </server>
    ...

This is working fine with Maven.

For xmllint, I’m trying the following:

xmllint --xpath 'string(//server[id="central"]/username/text())' ~/.m2/settings.xml 

For xmlstarlet, it is this:

xmlstarlet sel -T -R -D -t -v "//settings/servers/server[id='central']/username/text()" ~/.m2/settings.xml

Those are slightly semantically different, but I’ve tried several variations. All of these just print an empty string.