Al Phaba
Al Phaba

Reputation: 6755

How to extract the value of an xml attribute?

How can I extract the value autolex from this xml with xpath? Currently I am trying it with this xpath expression /Context[@path] but it returns the complete element.

I need only the value autolex

<?xml version="1.0" encoding="UTF-8"?>
<!-- neue Version des context.xml zum Deployment ausserhalb des Tomcat webapps-verzeichnis -->
<Context path="/autolex" 
         docBase="../../../applications/srs-autolex-1.1.1-0.war" 
         clearReferencesStatic="true" 
         unpackWAR="false" 
         reloadable="false">
  <Valve className="org.apache.catalina.valves.AccessLogValve"
    fileDateFormat="yyyy-MM-dd"
    pattern="%h %l %u %t &quot;%r&quot; %s %b &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;"
    prefix="autolex."
    suffix=".log"/>
  <ResourceLink global="pendb"
      name="jdbc/DataSource"
      type="javax.sql.DataSource"/>
  <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

Upvotes: 1

Views: 141

Answers (2)

MattH
MattH

Reputation: 38247

You need to select the attribute:

/Context/@path

Your original query, /Context[@path] selects Context elements with a path attribute.

Upvotes: 2

Ben
Ben

Reputation: 231

This should work: /Context/@path

Upvotes: 1

Related Questions