zoukankan      html  css  js  c++  java
  • 解析带有命名空间问题web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    	<filter>
        	    <filter-name>Filtername</filter-name>
        	    <filter-class>com.filter.Filtername</filter-class>
      	</filter>
    </web-app>


    解析过这样的web.xml根节点是带有命名名空间的,本来是想把xml里面的部分节点解析出来然后在增加到另一个web.xml当中

    但是增加完后就发现多了东西,就拿上面的filter为例


    <filter xmlns="http://java.sun.com/xml/ns/javaee">
        	    <filter-name>Filtername</filter-name>
        	    <filter-class>com.filter.Filtername</filter-class>
      	</filter>


    增加的时候节点调用element.detach();去掉原来根节点,命名空间就显示在了下一级节点上,
    下面用了个递归去掉了命名空间

    public void deleteNamespace(Element ele){
    		Element element = ele.setNamespace(null);
    		List childrenList = element.getChildren();
    		if(childrenList.size() > 0) {
    			for(int i = 0; i < childrenList.size(); i++) {
    				deleteNamespace((Element) childrenList.get(i));
    			}
    		} 
    	}


    可以把filter节点传进去
    其他方法暂时没有想到,节点有个ele.removeNamespaceDeclaration(additionalNamespace)试了下不行,不知道是不是用的不对。

  • 相关阅读:
    抽奖代码
    org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Session after a
    Cannot add or update a child row: a foreign key constraint fails
    SyntaxError:identifier starts immediately after numeric literal
    too much recursion
    微信处理红包
    minerd
    minerd
    kill常用
    阿里云centos 6安装Nginx+PHP+MySQL
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3323002.html
Copyright © 2011-2022 走看看