简体   繁体   English

无法使用Intellij Idea执行Xpath

[英]Can not execute Xpath with Intellij Idea

I try to execute xpath expression in web.xml in Intellij Idea 我尝试在Intellij Idea中的web.xml中执行xpath表达式

Xpath Expression Xpath表达式

//param-value[email]

Web.xml 在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! 此外,Idea强调param值,因为它不存在,当我clik ctrl + space时,我看不到标签! I try use this plugin in another project and another xml - it works, but in that case it is not. 我尝试在另一个项目和另一个xml中使用此插件 - 它可以工作,但在这种情况下它不是。

Any ideas? 有任何想法吗? May be I missed some configuration? 可能是我错过了一些配置?

UPDATED 更新

I remove attributes from web-app tag and expression start works. 我从web-app标签中移除属性,表达式开始工作。 But Why? 但为什么?

Firstly, the param-value element is in a namespace, but your XPath expression is looking for it in no namespace. 首先,param-value元素位于命名空间中,但是您的XPath表达式在没有命名空间的情况下查找它。 Typically you want an expression such as //j:param-value where the prefix j is bound to the namespace http://java.sun.com/xml/ns/j2ee - you'll have to check the IntelliJ documentation to see how to do that. 通常你需要一个表达式,如//j:param-value ,其中前缀j绑定到命名空间http://java.sun.com/xml/ns/j2ee - 你必须检查IntelliJ文档才能看到怎么做。

Secondly, your param-value elements do not have a child element called email . 其次,您的param-value元素没有名为email的子元素。 If you want the value of the associated param-name element to be "email", that would be 如果您希望关联的param-name元素的值为“email”,那就是

//j:context-param[j:param-name='email']/j:param-value

Try following: 试试以下:

  1. Open evaluate Xpath window (ctrl + shift + a: Evaluate Xpath) 打开评估Xpath窗口(ctrl + shift + a:Evaluate Xpath)
  2. Click Advanced button 单击高级按钮
  3. Add uri with prefix (on the screenshot below I have added Maven POM namespace with "pom" prefix) 添加带有前缀的uri(在下面的屏幕截图中,我添加了Maven POM名称空间,带有“pom”前缀)
  4. Try to evaluate "/pom:project" xpath on any pom.xml (notice that now IntelliJ autocompletes pom elements) 尝试在任何pom.xml上评估“/ pom:project”xpath(注意,现在IntelliJ自动填充pom元素)

Intellij评估表达式截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM