xmlstarlet有多个Namspaces

时间:2017-06-05 08:03:20

标签: xmlstarlet

我需要从XML中提取值并按需更新元素值。我试图使用xmlstarlet实用程序从XML中提取值,但它不适用于复杂的xml结构。

使用过的命令: cat server.xml | xml sel -NP = http://www.ibm.com/websphere/appserver/schemas/5.0/processexec.xmi -NC =“http://www.omg.org/XMI”-t -m“/ P:process / P:Server / P:processDefinitions / P:jvmEntries / P: classpath“-v。

      2       3       4       五       6       7       8       9      10      11      12      13      14      15      16

17

179     <components xmi:type="applicationserver.sipcontainer:SIPContainer" xmi:id="SIPContainer_1450084659639" name="" maxAppSessions="120000" maxMessageRate="5000" maxDispat        chQueueSize="3200" maxResponseTime="0" statAveragePeriod="1000" statUpdateRange="10000">
180       <stack xmi:id="Stack_1450084659639">
181         <timers xmi:id="Timers_1450084659639"/>
182       </stack>
183     </components>
184     <webserverPluginSettings xmi:id="WebserverPluginSettings_1450084659639" WaitForContinue="false" ConnectTimeout="60" MaxConnections="80" ExtendedHandshake="false" Serv        erIOTimeout="600"/>
185   </components>
186   <processDefinitions xmi:type="processexec:JavaProcessDef" xmi:id="JavaProcessDef_1450084659639" workingDirectory="${USER_INSTALL_ROOT}" executableTargetKind="JAVA_CLASS        " executableTarget="com.ibm.ws.runtime.WsServer">
187     <execution xmi:id="ProcessExecution_1450084659639" processPriority="20" runAsUser="" runAsGroup=""/>
188     <ioRedirect xmi:id="OutputRedirect_1450084659639" stdoutFilename="${SERVER_LOG_ROOT}/native_stdout.log" stderrFilename="${SERVER_LOG_ROOT}/native_stderr.log"/>
189     <monitoringPolicy xmi:id="MonitoringPolicy_1450084659639" maximumStartupAttempts="3" pingInterval="600" pingTimeout="300" autoRestart="false" nodeRestartState="STOPPE        D"/>
190     <jvmEntries xmi:id="JavaVirtualMachine_1450084659639" verboseModeClass="false" verboseModeGarbageCollection="true" verboseModeJNI="false" initialHeapSize="3072" maxim        umHeapSize="3072" runHProf="false" hprofArguments="" debugMode="false" debugArgs="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=7777" genericJvmArguments=        "-Demt.was.appname=LOBCProfile01 -Demt.was.debug=false -Demt.was.home=/upppasr1/ZIBEUAT2/was-bin/ZIBE/emt-was/855 -Demt.core.home=/upppasr1/ZIBEUAT2/was-bin/ZIBE/emt-was/        855 -Dcom.ibm.websphere.security.util.createBackup=false -Dcom.ibm.wsspi.security.crypto.customPasswordEncryptionClass=com.itic.emt.was.security.CustomEncryptionImpl -Dco        m.ibm.wsspi.security.crypto.customPasswordEncryptionEnabled=true -Demt.was.servername=APP_A1_KHBCG -Xmn512M -Xverify:none -Xgcpolicy:gencon -Xdisableexplicitgc -Xverboseg        clog:${SERVER_LOG_ROOT}/native_stderr.log.%Y%m%d.%H%M%S.%pid,7,10000  -javaagent:/opt/appdyn/javaagent-ibm/4.2.1.8/javaagent.jar -Dappdynamics.controller.hostName=appdyn-        nam-gcg-test-2.nam.nsroot.net -Dappdynamics.controller.port=8181 -Dappdynamics.agent.applicationName=153583_GCB-LOBC-GM-HK_APAC_UAT -Dappdynamics.agent.nodeName=tcwgwm-LO        BCa09u_null_APP_A1_KHBCG -Dappdynamics.agent.tierName=LOBC_HK_WAS -Dappdynamics.agent.logs.dir=/upppwsr1/ZIBEUAT2/was-apps/ZIBE/ZIBE_Runtime/profiles/ZIBECell/LOBCProfile        01/logs/APP_A1_KHBCG -Dappdynamics.controller.ssl.enabled=true -Dappdynamics.force.default.ssl.certificate.validation=true -Dappdynamics.agent.accountName=customer1 -Dapp        dynamics.agent.accountAccessKey=ef0334ff-7c79-4f78-a7eb-7d2fa4e0a325 -Dappdynamics.agent.ssl.protocol=TLSv1.2" executableJarFileName="" disableJIT="false">
191       <classpath>/anc/sdfd/jab.jar:[]</classpath>
192       <systemProperties xmi:id="Property_1450084659646" name="com.ibm.security.jgss.debug" value="off" required="false"/>
193       <systemProperties xmi:id="Property_1450084659647" name="com.ibm.security.krb5.Krb5Debug" value="off" required="false"/>
194       <systemProperties xmi:id="Property_1450697072560" name="HttpSessionReaperPollInterval" value="30" required="false"/>
195       <systemProperties xmi:id="Property_1450697072628" name="config_consistency_check" value="false" required="false"/>
196       <systemProperties xmi:id="Property_1450697072647" name="javax.net.debug" value="false" required="false"/>
197        <systemProperties xmi:id="Property_1465366047008" name="com.ibm.websphere.webservices.DisableIBMJAXWSEngine" value="true" required="false"/>
198     </jvmEntries>
199   </processDefinitions>
200 </process:Server>

1 个答案:

答案 0 :(得分:0)

似乎您的给定xml未满。但是,我清楚地了解到,您试图解析websphere appserver server.xml。它可以很容易地实现。 附上脚本供您理解。希望它能满足您的要求。

echo&#34; JVM条目&#34; cat server.xml | xmlstarlet sel -t \ -m&#34; / process:Server / processDefinitions / jvmEntries&#34; -v&#34; concat(&#39; InitialHeapSize:&#39;,@ initialHeapSize,&#39; MaximumHeapSize:&#39;,@ maximumHeapSize)&#34; -n \ -m&#34; / process:Server / processDefinitions / jvmEntries / @ verboseModeGarbageCollection&#34; -v&#34; concat(&#39; verboseModeGarbageCollection&#39;,@ verboseModeGarbageCollection)&#34; -n \ -m&#34; / process:Server / processDefinitions / jvmEntries / @ genericJvmArguments&#34; -v&#34; concat(&#39; GenericJvmArguments:&#39;,。)&#34; -n \ -m&#34; / process:Server / processDefinitions / jvmEntries / systemProperties&#34; -v&#34; concat(&#39; JvmPropertyName:&#39;,@ name,&#39; Value:&#39;,@ value)&#34; -n echo&#34; ThreadPools&#34; cat server.xml | xmlstarlet sel -t -m&#34; / process:Server / services / threadPools&#34; -v&#34; concat(&#39; ThreadPoolName:&#39;,@ name,&#39; 〜&#39;,&#39; minimumSize:&#39;,@ minimumSize,& #39; 〜&#39;&#39; MAXIMUMSIZE:&#39;,@ MAXIMUMSIZE,&#39; *〜&#39;&#39; inactivityTimeout:&#39;,@ inactivityTimeout)&#34; -n

xmlstarlet sel -t -m&#34; / process:Server / services / threadPools [@name =&#39; WebContainer&#39;]&#34; -v&#34; concat(&#39; ThreadPoolName:&#39;,@ name,&#39; 〜&#39;,&#39; minimumSize:&#39;,@ minimumSize,& #39; 〜&#39;&#39; MAXIMUMSIZE:&#39;,@ MAXIMUMSIZE,&#39; *〜&#39;&#39; inactivityTimeout:&#39;,@ inactivityTimeout)&#34; server.xml中