xmlstarlet-通过其参数名称

时间:2018-01-02 11:04:51

标签: xml xpath xmlstarlet

我想通过命令行更新xml文件中的值。我是xmlstartlet的新手我尝试使用以下命令将值更新为欢迎文件节点上的login.jsp

xml ed -L -N x="http://java.sun.com/xml/ns/javaee" -u "/x:web-app/x:welcome-file-list/x:welcome-file" -v 'Login.jsp' web.xml

这是有效的,但我还有一个更改,但在xml中它有多个同名的节点。

示例:

<param-name>**AuthMode**</param-name>
<param-value>SnRWithBypass</param-value>

需要更改为

<param-name>**AuthMode**</param-name>
<param-value>SnR</param-value>

通过参数名称AuthMode可以读取和更新参数值。

这是我的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">
    <display-name>Struts2 Application</display-name>

<error-page>
    <error-code>404</error-code>
    <location>/ErrorPage.jsp</location>

  </error-page>

  <error-page>
    <error-code>403</error-code>
    <location>/ErrorPage.jsp</location>

  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/ErrorPage.jsp</location>

  </error-page>

<error-page> 
<exception-type>java.lang.Throwable</exception-type> 
<location>/ErrorPage.jsp</location> 
</error-page> 

<listener>
        <listener-class>com.tcs.bancs.listener.SessionListener</listener-class>
</listener>


<!--  Commenting as per discussion -->

<!-- 
<filter>
    <display-name>CompressionFilter</display-name>
    <filter-name>CompressionFilter</filter-name>
    <filter-class>com.tcs.bancs.web.filter.CompressionFilter</filter-class>

    <init-param>
      <param-name>excludeURI</param-name>
      <param-value>documentDownloadIFADD,</param-value>
    </init-param>

  </filter>
  <filter-mapping>
    <filter-name>CompressionFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  -->


 <!-- WI Auth filter changes by Tuhin -->

 <filter>
    <display-name>WIAuthFilter</display-name>
    <filter-name>WIAuthFilter</filter-name>
    <filter-class>com.tcs.bancs.web.filter.WIAuthFilter</filter-class>
    <init-param>
            <param-name>userHeader</param-name>
            <param-value>OAM_REMOTE_USER</param-value>
    </init-param>
    <init-param>
      <param-name>excludeParam</param-name>
      <param-value>filterCriteria,svgDataForPublishPlan,svgChart,hiddeninvstmntvalue,idHidden2,bankName,clientLabelData,monitoredJson,pageTitleLbl,hiddenVariable3,tableThruResponseMonitored,ToolTip,ReasonsDropBox,confirmSvgData,currencyCombo_Tooltip,cancelInsDescrip,bankingDetailTable_RowValue,editInsDescrip,OneOffEditLink_Title,riskLevelTable,svgDataForReportPlan,paginationData,tableThruResponseLive,tableApplicationPytMthdOne_RowValue,savingsTable_RowValue,lumpsumContributionTableOne_RowValue,paymentTable_RowValue,premiumTable_RowValue,confirmationOfChargesTable_RowValue,fundadviserTable1_RowValue,livesassuredTable_RowValue,lumpsumOriginofwealthTable_RowValue,collectiveSector,transactionData,onBackFlag,hiddenPagination
     ,filterEdit,filtersArrayVal,Filters,chkBoxArrayVal,warningTxtD,warningTxtR,filtersFromCurrent,AssetClassCombo,SectorCombo,RegularWithdrawalJSON,RWJosn,hiddenVariable6,tableThruAjax,documentName</param-value>
    </init-param>
    <init-param>
            <param-name>loginURI</param-name>
            <param-value>/login</param-value>
    </init-param>
    <init-param>
            <param-name>realexURI</param-name>
            <param-value>/RealexServlet.srl</param-value>
    </init-param>
    <init-param>
            <param-name>logoutURI</param-name>
            <param-value>/logout.action</param-value>
        </init-param>
                <!-- downloadURI                               
                               To download static content we should use below path, do not add any other url in this param
                 -->
         <init-param>
             <param-name>downloadURI</param-name>
             <param-value>/_static_contents_/download</param-value>
        </init-param>
        <init-param>
                        <param-name>AuthMode</param-name>
                        <!-- Modes: 
                                SnROnly - default, only SnR URL will be allowed, 
                                SnRWithBypass- login bypass will be allowd (onsite test), 
                                NoSnR - No SnR, filter will be disabled (Offshore Only) 
                        -->
                        <!-- To use SnROnly/ SnRWithBypass we need to make sure 
                            1: jaas config
                                BFS{
                                   com.tcs.bfsarch.security.module.BFSSiteMinderLoginModule required debug=true;
                                };

                            2:MCSystem.prop
                                singleSignon=yes

                            3:DB script change
                               In security_parameter table entry singlesignon=3 for systemid 2(extranet)

                        -->
                        <param-value>SnRWithBypass</param-value>
        </init-param>
        <init-param>
                        <param-name>logfile</param-name>
                        <param-value>E:\BancsProduct\logs\wiauth.log;10M</param-value>
        </init-param>
  </filter>
  <filter-mapping>
    <filter-name>WIAuthFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

<filter>
    <display-name>StaticContentFilter</display-name>
    <filter-name>StaticContentFilter</filter-name>
    <filter-class>com.tcs.bancs.web.filter.StaticContentFilter</filter-class>

    <!-- 
     * Parameter Name: staticContextRoot -> the sub context root for static context in the formed virtual path
     * Mandatory
     * Fingerprint (MD5 hash of the file) will follow this sub context root
     -->
    <init-param>
      <param-name>staticContextRoot</param-name>
      <param-value>_static_contents_</param-value>
    </init-param>

    <!-- 
     * Parameter Name: contentTypes -> the comma separate list content type considered for URI replacement in the response body
     * Mandatory
     -->
    <init-param>
      <param-name>contentTypes</param-name>
      <param-value>text/html,text/css,application/javascript,text/plain</param-value>
    </init-param>



    <!-- 

* Parameter Name: CacheExpiryInSeconds -> no of seconds after which cache will expire in browser

* Optional

* Default Value = 31536000 (1 Year) 

--> 

<init-param>

<param-name >CacheExpiryInSeconds </param-name>

<param-value> 31536000 </param-value>

</init-param>

<!-- 

       * Parameter Name: staticContentExtensions 

       * Optional

       * Default Value = .css,.html,.htm,.pdf,.jpg,.jpeg,.png,.gif,.js

       * Comma seperated list of extension for which the URI replacement will be done


-->
    <init-param>

      <param-name>staticContentExtensions</param-name>

      <param-value>.css,.html,.htm,.pdf,.jpg,.jpeg,.pjpeg,.png,.gif,.js</param-value>

    </init-param>





    <!-- 
     * Parameter Name: maxFileSizeToReplace -> Size in bytes or in KB (K) or MB (M)
     * Optional
     * Default Value = 512M
     * This controls the static file replacement - if any static file is more than specified size,
     * that will not be considered for URI replacement inside the file 9to avoid too much memory consumption)

    <init-param>
      <param-name>maxFileSizeToReplace</param-name>
      <param-value>512M</param-value>
    </init-param>
    -->
    <!-- 
     * Parameter Name: ignoreURIs -> the comma separate list of URIs (exlusive of context root path), which will be ignored for URI replacement inside
     * Optional
     * Default Value = Blank list
     * The URIs mentioned will be skipped URI replacements

    <init-param>
      <param-name>ignoreURIs</param-name>
      <param-value>/path1,/path2</param-value>
    </init-param>
 -->
    <init-param>
      <param-name>ignoreURIs</param-name>
      <param-value>/realexNvgtn</param-value>
    </init-param>
 <!-- 
     * Parameter Name: listNonReplacableURIs -> the comma separate list of URIs (exlusive of context root path), which will not be replaced
     * Optional
     * Default Value = Blank list
     * The URIs mentioned will be not be replaced if used in response as script, CSS or image inclusion
     -->
    <init-param>
      <param-name>listNonReplacableURIs</param-name>
      <param-value>/alfresco.srl</param-value>
    </init-param>

    <!-- 
     * Parameter Name: logfile -> logfile name and size
     * Format : <Logfile path>;Size -> logfile path could be a directory or full path including file name, size could be in bytes, KB (K) or MB (M)
     * Ex : /usr/log/abc.log;10M
     * Optional 
     * Default Value = if nothing specified, logging will be off. If size is not specified or invalidly specified default will be 5MB
     * If file is specified and writable then log will be written in that path. 
     * If the path is directory the "staticfilter.log" file will be created under the path.
     * Log will be rotated after the size reached the size mentioned (default 5MB)
     -->
    <init-param>
      <param-name>logfile</param-name>
      <param-value>E:\BancsProduct\staticfilter.log;10M</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>StaticContentFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


  <!--  CSRF Vulnerability -->
     <filter>
            <filter-name>CSRFShield</filter-name>
            <filter-class>com.tcs.bancs.csrfguard.CSRFShieldFilter</filter-class>
            <init-param>
                    <param-name>config</param-name>
                    <param-value>WEB-INF/csrfguard.properties</param-value>
            </init-param>
    </filter>


    <filter-mapping>
            <filter-name>CSRFShield</filter-name>
            <url-pattern>/*</url-pattern>
    </filter-mapping>  

 <!--  CSRF Vulnerability -->



    <!--<filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>




 <servlet>
    <servlet-name>WMPInitServlet</servlet-name>
    <servlet-class>com.tcs.wm.servlet.WMPInitServlet</servlet-class>

    <load-on-startup>2</load-on-startup>        
  </servlet>-->

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 <servlet>
    <servlet-name>WMPInitServlet</servlet-name>
    <servlet-class>com.tcs.wm.servlet.WMPInitServlet</servlet-class>

    <load-on-startup>2</load-on-startup>        
  </servlet>

<servlet>
    <description>
    </description>
<servlet-name>RealexServlet</servlet-name>
    <servlet-class>
    com.tcs.bancs.realexskandia.RealexServlet</servlet-class>   
    <load-on-startup>4</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>RealexServlet</servlet-name>
    <url-pattern>/RealexServlet.srl</url-pattern>
</servlet-mapping>



<servlet>
    <servlet-name>alfresco</servlet-name>
    <servlet-class>com.tcs.bancs.wcm.servlet.HttpProxyServlet</servlet-class>
    <init-param>
    <param-name>log</param-name>
    <param-value>true</param-value>
    </init-param>
</servlet>
<servlet-mapping>
     <servlet-name>alfresco</servlet-name>
     <url-pattern>/alfresco.srl/*</url-pattern>
</servlet-mapping> 


<servlet>
    <description>
    </description>
    <display-name>
    AplStartup</display-name>
    <servlet-name>AplStartup</servlet-name>
    <servlet-class>
    iims.workflow.util.AplStartup</servlet-class>   
    <load-on-startup>4</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>AplStartup</servlet-name>
    <url-pattern>/AplStartup</url-pattern>
</servlet-mapping>

<servlet>
    <description>
    </description>
    <display-name>
    DMSStartup</display-name>
    <servlet-name>DMSStartup</servlet-name>
    <servlet-class>
    dms.DMSStartup</servlet-class>  
    <load-on-startup>3</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>DMSStartup</servlet-name>
    <url-pattern>/DMSStartup</url-pattern>
</servlet-mapping>

<servlet>
    <description>
    </description>
    <display-name>
    IIMSStartup</display-name>
    <servlet-name>IIMSStartup</servlet-name>
    <servlet-class>
    iimsStartup.IIMSStartup</servlet-class> 
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>IIMSStartup</servlet-name>
    <url-pattern>/IIMSStartup</url-pattern>
</servlet-mapping>
<servlet>
    <description>
    </description>
    <display-name>
    IIMSStartupNext</display-name>
    <servlet-name>IIMSStartupNext</servlet-name>
    <servlet-class>
    iimsStartup.IIMSStartupNext</servlet-class>
    <load-on-startup>2</load-on-startup>
</servlet>  
<servlet-mapping>
    <servlet-name>IIMSStartupNext</servlet-name>
    <url-pattern>/IIMSStartupNext</url-pattern>
</servlet-mapping>
<servlet>
    <servlet-name>TreeServlet</servlet-name>
    <servlet-class>iimsStartup.TreeServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>TreeServlet</servlet-name>
    <url-pattern>/TreeServlet</url-pattern>
</servlet-mapping>

  <session-config>
        <session-timeout>30</session-timeout>
  </session-config> 

  <mime-mapping>
    <extension>doc</extension>
    <mime-type>application/doc</mime-type>
  </mime-mapping>
  <mime-mapping>
      <extension>pdf</extension>
      <mime-type>application/pdf</mime-type>
  </mime-mapping>
  <mime-mapping>
        <extension>csv</extension>
        <mime-type>application/vnd.ms-excel</mime-type>
  </mime-mapping>

  <mime-mapping> 
    <extension>js</extension> 
    <mime-type>application/javascript</mime-type> 
  </mime-mapping> 

  <mime-mapping> 
        <extension>png</extension> 
        <mime-type>image/png</mime-type> 
    </mime-mapping> 

    <welcome-file-list>
        <welcome-file>LoginSR.jsp</welcome-file>
    </welcome-file-list>


    <jsp-config>
        <taglib>
            <taglib-uri>/tags/ebw-taglibs</taglib-uri>
            <taglib-location>/WEB-INF/ebwtaglibs.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/CSRFGuard-taglibs</taglib-uri>
            <taglib-location>/WEB-INF/CSRFGuard.tld</taglib-location>
        </taglib>

        <taglib>
        <taglib-uri>/tags/c</taglib-uri>
        <taglib-location>/WEB-INF/c.tld</taglib-location>
     </taglib>

     <taglib>
        <taglib-uri>/tags/wcm</taglib-uri>
        <taglib-location>/WEB-INF/WCM.tld</taglib-location>
     </taglib>

    </jsp-config>

</web-app>

1 个答案:

答案 0 :(得分:1)

我建议:

--update "//x:init-param[x:param-name='AuthMode']/x:param-value" -v "SnR"