3

I try to execute xpath expression in web.xml in Intellij Idea

Xpath Expression

//param-value[email]

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app  version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Archetype Created Web Application</display-name>
    <servlet>
        <servlet-name>ServletName</servlet-name>
        <servlet-class>com.ServletDemo</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>ServletName</servlet-name>
        <url-pattern>/Demo1</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>email</param-name>
        <param-value>admin@email.com</param-value>
    </context-param>
</web-app>

And I have no results. Moreover Idea highlight param-value as it does not exist and when I clik ctrl+space I see no tags! I try use this plugin in another project and another xml - it works, but in that case it is not.

Any ideas? May be I missed some configuration?

UPDATED

I remove attributes from web-app tag and expression start works. But Why?

4

2 回答 2

5

首先,param-value 元素在命名空间中,但您的 XPath 表达式在没有命名空间中寻找它。通常,您需要一个表达式,例如//j:param-value前缀 j 绑定到命名空间http://java.sun.com/xml/ns/j2ee - 您必须查看 IntelliJ 文档以了解如何执行此操作。

其次,您的 param-value 元素没有名为email. 如果您希望关联param-name元素的值是“电子邮件”,那就是

//j:context-param[j:param-name='email']/j:param-value
于 2013-07-30T10:20:08.233 回答
2

尝试以下操作:

  1. 打开评估 Xpath 窗口(ctrl + shift + a:评估 Xpath)
  2. 单击高级按钮
  3. 添加带有前缀的 uri(在下面的屏幕截图中,我添加了带有“pom”前缀的 Maven POM 命名空间)
  4. 尝试在任何 pom.xml 上评估“/pom:project”xpath(注意现在 IntelliJ 自动完成 pom 元素)

Intellij Evaluate 表达式截图

于 2016-06-24T00:44:46.387 回答